Abstract Grammar and Abstract Syntax Tree: The Grammar Is Not Parser Friendly
Abstract Grammar and Abstract Syntax Tree: The Grammar Is Not Parser Friendly
In programming languages, we prefer a grammar that is close to the language constructs. We call this grammar the abstract grammar. The corresponding derivation tree is called the abstract syntax tree. A node represents a language construct, a leaf represents a token. E E E E E +E E E num id
More particularly: we use concrete grammar to construct parsers, but we insert code into parser implementation to explicitly generate abstract syntax tree.
2
public class IdExp extends Exp { private String f0; public IdExp(String n0) { ... } int evalVisit() { return getVarValue(f0); } } public class IntExp extends Exp { private int v; public IntExp (int n0) { ... } int evalVisit() { return v; } }