How to turn a token stream into a parse tree

I have a built-in lexer that outputs tokens from the input, but I'm not sure how to build the next step in this process - the parsing tree. Does anyone have any good resources or examples of how to do this?

+3
source share
4 answers

I would recommend http://www.antlr.org/ and, of course, the book of classic dragons.

For a simple language such as JavaScript, it's not difficult to manually steer a recursive descent parser, but it is almost always easier to use a tool like yacc or antlr.

, , BNF-esque . , , "" .

, (, - ). ; , , " ".

+4

. - . , "" . , . , :

%left PLUS, MINUS           # low precedence, evaluated left-to-right
%left TIMES, DIV            # high precedence, left-to-right

expr ::= INT
| expr PLUS expr
| expr MINUS expr
| expr TIMES expr
| expr DIV expr
| LEFT_PAREN expr RIGHT_PAREN

, ( ) . , .

. ANTLR C, ++, Objective C, Java Python. , . bison C/++, CUP Java ocamlyacc OCaml, . , , .

+2

, . , , , , node ..

0

, , BNF , , . , , , Pushdown-Automaton, FiFo. , . "" , , ( , , ). () ( ) , , .

Antlr , (waaay ). !

0

All Articles