CoNNeTTivo
Ritorna al Sommario

Arte e Grafica

Arte In Movimento

Auto-aiuto informatico

CDA Anomalia

Comunicoscopio

CoNNeTTivo

Gr(A)fismo

Ocamlearn

Radar di Pace
Ocamlearn
Abstract Syntax Tree: understanding made-to-measure syntax
mercoledì 2 luglio 2003





NELLA STESSA RUBRICA :
>7 marzo 2003
>5 marzo 2003
PAROLE CHIAVE ASSOCIATE :





ARTICOLI CON LO STESSO TEMA :


ABSTRACT SYNTAX TREES

  The "concrete syntax" of a program, in our case of an expression, is the
  syntax the programmer use while writing it. The "abstract syntax" is a
  representation of what the concrete syntax means. An "abstract syntax tree"
  (AST for short) is a tree representation of the abstract syntax. A syntax tree
  representation as no more associativity and precedence problems.

So after parsing the string "1*(2+x)*(y-10)" we get the AST:

Ast.Times (Ast.Times (Ast.Int 1, Ast.Plus (Ast.Int 2, Ast.Ident "x")), Ast.Minus (Ast.Ident "y", Ast.Int 10))

that is: * / \ / \ * - / \ | \ 1 + y 10 / \ 2 x

Having an AST and a mapping from variable names to variable values you can easily compute the value of an expression with a recursive function.

You can download an example of parsing a AST with ocamllex/ocamlyacc and an example of parsing a AST with stream parsers here.

© Stefano ’’Zack’’ Zacchiroli GNU FDL + GPL 2003

CoNNeTTivo   



© 2003 realizzato e concepito da ernestor + arlok + oSi + Z.
Questo sito usa PHP e mySQL ed è realizzato con software in licenza GNU/GPL.
Tutti i testi contenuti in questo sito sono COPYRIGHT dei loro autori.

fil XML