bnfc

Using BNFC to determine a basic language for propositional logic (syntax error)

僤鯓⒐⒋嵵緔 提交于 2020-04-17 22:10:13
问题 I would like to parse sentences in propositional logic using BNFC. I wrote the following BNF grammar to facilitate this: Negation. N ::= "(" "-" L")"; Conjuction. C ::= "(" L "&" L ")"; Disjuction. D ::= "(" L "|" L ")"; Implication. I ::= "(" L "=>" L ")"; Equivalence. E ::= "(" L "<=>" L ")"; Atom. L ::= Ident | N | C | D | I | E ; However, with this construction I get the following error: syntax error at line 6, column 27 before `|' What is syntactically incorrect about the specification I

Parser in C# and printing AST

左心房为你撑大大i 提交于 2019-12-25 07:09:28
问题 I am implementing an AST (Abstract Syntax Tree) in C# for a complex grammar, however, to make this question simple, I will use a very simple grammar. Consider this grammar: rules Expr ::= Term "+" Term | Term ; rules Term ::= Ident | Integer ; I have used bnfc and generated the parser/lexer and got to the point that I can parse a piece of code and can print the parse tree. Now I want to map it to AST, and print the Abstract Syntax Tree. here is what I have done so far in a sample project.

Parser in C# and printing AST

依然范特西╮ 提交于 2019-12-25 07:07:20
问题 I am implementing an AST (Abstract Syntax Tree) in C# for a complex grammar, however, to make this question simple, I will use a very simple grammar. Consider this grammar: rules Expr ::= Term "+" Term | Term ; rules Term ::= Ident | Integer ; I have used bnfc and generated the parser/lexer and got to the point that I can parse a piece of code and can print the parse tree. Now I want to map it to AST, and print the Abstract Syntax Tree. here is what I have done so far in a sample project.