Hello!
It is possible a little theory / practice on creation of the elementary interpreter of a text / tag marking. Need to:

  • Develop a font type markup tag,
  • Develop a text color markup tag,
  • Develop a font size markup tag,
  • Develop a pattern markup tag
  • Develop a tag marking the coordinates of elements on the form,
  • Develop a document background tag,
  • Develop a document title tag,
  • Develop a newline tag.

The language is almost unimportant, but preferable to Lisp, C / C ++, Java, Erlang, Prolog. (I used them at least somehow). What to learn it, what to see?


I understand that the question is simply “pearl”, to say simply “algorithm” for a whole huge section of computer science is to say nothing. But still - distribute the material.

  • Another crazy inventor ... - Barmaley
  • Why did the inventor immediately? .. I just found a task on the Internet, but I don’t know the methods for solving such tasks. I have never contacted the creation of interpreters. - Sasha Gavrilov
  • I understand what sounds naive and how stupid, but simply and frankly. Yes - idiot, yes - clinic. Well, so what and the interpreter can not write? Give sources to learn and better with more practical examples. - Sasha Gavrilov
  • one
    This is called lexical analysis and parsing. The only source I know of is right on hardcore - a dragonbook: Alfred V. Aho, Monica S. Lam, Ravi Seti, Jeffrey D. Ulman. Compilers: principles, technologies and tools. But maybe according to this information there will be something else. - Alex Krass
  • four
    > Another crazy inventor..and what, to write your bikes in order to self-development is madness? - DreamChild

2 answers 2

See it.

If the language is in your hands, think of it so that it is convenient to parse. But of course, and easy to use! Try expressing simple markup on it, see how easy it is.

I would do something like BBCode, in the end, the format is known, easy to parse, read by human beings, and it seems to meet your requirements. (Plus, there are ready-made parsers for it.) For it, the recursive descent parser will completely roll back (a light and self-evident thing that can be written by hand).

You can still pragmatically take XML, then the syntax analysis you trust one of the billion ready-made libraries, while you yourself are engaged in the implementation of the semantic part.

As a literature, the Dragon Book (a classic but complex book), mentioned in the comments, comes first. If you want to start with something easier, read Wirth's 5th chapter “Algorithms + Data Structures = Programs”, a very easy and pleasant introduction to the topic.

A specific language is really unimportant. Although of course if you are good at Lisp, what are we talking about then?

  • Yes thank you. Not very I own. Simply, the best and fastest surrendered labs in the university =) - Sasha Gavrilov
  • one
    The main thing is not to take by mistake the latest editions of "Algorithms and Data Structures", this chapter is absent there. - AlexeyM

@Mypowerfulbrain you obviously have trouble with logic.

I will explain:

Develop font type markup tag

what is it about? And where is Lisp, C / C ++, Java, Erlang, Prolog?

If the question was formulated as follows:

Develop a font type markup parser

That is not a question - it is a task for a programming language.

You develop your markup language and ask how to write a parser to it, for example:

[шрифт]Это мой текст]тфирш[ 

This is a markup and it is easy to write a parser to it.

  • Can you give an example of a parser for any one tag, for example, a font of a certain size, in any of the languages ​​(Lisp, C / C ++, Java, Erlang, Prolog)? - Sasha Gavrilov
  • @Mypowerfulbrain: There is no tag parser, there is a language / grammar parser. An example of a small parser can be seen, for example, here . - VladD
  • @Mypowerfulbrain is not sufficiently lacking other conditions, such as whether tags can be nested, tags can have attributes, and so on. However, in the dull case, the parser will be of the type: public String getTagBody(String text, String tag) { String startTag="<"+tag+">"; String endTag="<\"+tag+">"; int startIndex=text.indexOf(startTag); if(startIndex==-1) return null; int endIndex=text.indexOf(startIndex+startTag.length(), endTag); if(endIndex==-1) throw MalformedTagExpeption(); return text.subString(startIndex, endIndex); } public String getTagBody(String text, String tag) { String startTag="<"+tag+">"; String endTag="<\"+tag+">"; int startIndex=text.indexOf(startTag); if(startIndex==-1) return null; int endIndex=text.indexOf(startIndex+startTag.length(), endTag); if(endIndex==-1) throw MalformedTagExpeption(); return text.subString(startIndex, endIndex); } public String getTagBody(String text, String tag) { String startTag="<"+tag+">"; String endTag="<\"+tag+">"; int startIndex=text.indexOf(startTag); if(startIndex==-1) return null; int endIndex=text.indexOf(startIndex+startTag.length(), endTag); if(endIndex==-1) throw MalformedTagExpeption(); return text.subString(startIndex, endIndex); } In general, we need a grammar - Barmaley
  • Parsers, of course, are not written - for such a "code" the parsers can also load with felt boots. Usually parsers are written with handlers (callbacks) - see for example XML SAX parser - Barmaley