We need examples with the analysis of similar tasks with comments. I did not understand the example that I wrote. Help with the task, on the Internet in general there is nothing good on this topic. Here is the task
Closed due to the fact that off-topic participants Kromster , aleksandr barakin , pavel , Alexander Petrov , Denis Oct 20 '16 at 6:37 .
It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:
- “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Kromster, pavel, Alexander Petrov, Denis
2 answers
In professional programming, the standard is a bunch of flex / bison. Specifically, bison refers to parsing. Network usage examples:
Plex / Pyacc will not go? http://wiki.freepascal.org/Plex_and_Pyacc For C / C ++ I always use the flex / bison (or lex / yacc for pure C) bundle + my universal base class for storing the received data (*) - quickly, easily, comes bundled with any GNU toolchain build (in particular MinGW).
struct Sym { string tag; // тэг типа, указывает тип значения string val; // значение объекта в текстовом представлении Sym(string T,string V); Sym(string V); // конструкторы: полный и sym- vector<Sym*> nest; void push(Sym*); // упорядоченные вложенные данные map<string,Sym*> lookup; // именованные поля virtual string head(); string pad(int);// \ вывод дампа объекта в виде дерева virtual strign dump(int depth); // / }; struct Integer:Sym { Integer(string); long long val; string head(); }; struct Number:Sym { Number(string); double val; string head(); };
The theory is described in detail in the Book of the Dragon, if you need a full-fledged own implementation, rather than coursework - look for algorithms for the synthesis of finite automata for regular expressions and EBNF grammars.
If for coursework and manual parsing is needed (lex / yacc generators are not suitable), adapt the compiler writing manual for LLVM under pascal:
- Kaleidoscope: Tutorial Introduction and the Lexer http://llvm.org/docs/tutorial/LangImpl01.html
- Kaleidoscope: Implementing a Parser and AST ht tp: //llvm.org/docs/tutorial/LangImpl02.html