parser-generator

What are features of ANTLR that XText Does not provide?

别等时光非礼了梦想. 提交于 2019-11-30 21:57:00
问题 I just came across very nice tool Xtext to create DSL as well as IDE for editing. I did some search on the web and found people saying it does not provide all the features of ANTLR. I am using ANTLR as my parser generator. I am not even sure what features of ANTLR I will need to write complete parser for my language but ANTLR is around for quite a long time and probably supports more features than Xtext. Can anyone please give some examples of what CANNOT be specified in a Xtext grammar? 回答1:

Can parser error recovery be guided automatically by the grammar?

ぐ巨炮叔叔 提交于 2019-11-30 14:17:00
问题 I'm writing an LALR parser generator as a pet project. I'm using the purple dragon book to help me with the design, and what I gather from it is that there are four methods of error recovery in a parser: Panic mode: Start dumping input symbols until a symbol pre-selected by the compiler designer is found Phrase-level recovery: Modify the input string into something that allows the current production to reduce Error productions: Anticipate errors by incorporating them into the grammar Global

Can parser error recovery be guided automatically by the grammar?

本秂侑毒 提交于 2019-11-30 09:55:44
I'm writing an LALR parser generator as a pet project. I'm using the purple dragon book to help me with the design, and what I gather from it is that there are four methods of error recovery in a parser: Panic mode: Start dumping input symbols until a symbol pre-selected by the compiler designer is found Phrase-level recovery: Modify the input string into something that allows the current production to reduce Error productions: Anticipate errors by incorporating them into the grammar Global correction: Way more complicated version of phrase-level recovery (as I understand it) Two of these

Language parser library written in PHP

谁都会走 提交于 2019-11-30 07:24:54
I am looking for a language parser written in PHP . The goal is to read a custom language , not read PHP code. Basically, I want to specify a language syntax, give a code snippet and get back a structure representing it. Then I can traverse that structure to execute the code snippet. I believe the structure will be an AST , but I don't know if this is the only option (I am not intimate with parsers and their vocabulary). I had a look at the Doctrine DQL parser but it doesn't seem like a generic language parser. This is not a complete list, if you're looking for PHP runtime lexer/parsers, one

How to create a parser(lex/yacc)?

喜你入骨 提交于 2019-11-30 05:57:11
I'm having the following file and which need to be parsed --TestFile Start ASDF123 Name "John" Address "#6,US" end ASDF123 The lines start with -- will be treated as comment lines. and the file starts 'Start' and ends with end . The string after Start is the UserID and then the name and address will be inside the double quots. I need to parse the file and write the parsed data into an xml file. So the resulting file will be like <ASDF123> <Name Value="John" /> <Address Value="#6,US" /> </ASDF123> now i'm using pattern matching( Regular Expressions ) to parse the above file . Here is my sample

ANTLR Parser with manual lexer

别等时光非礼了梦想. 提交于 2019-11-30 04:13:07
I'm migrating a C#-based programming language compiler from a manual lexer/parser to Antlr. Antlr has been giving me severe headaches because it usually mostly works, but then there are the small parts that do not and are incredibly painful to solve. I discovered that most of my headaches are caused by the lexer parts of Antlr, rather than the parser. Then I noticed parser grammar X; and realized that perhaps I could have my manually written lexer and then an Antlr generated parser. So I'm looking for more documentation on this topic. I guess a custom ITokenStream could work, but there appears

How can I build a Truth Table Generator?

霸气de小男生 提交于 2019-11-30 03:38:34
I'm looking to write a Truth Table Generator as a personal project. There are several web-based online ones here and here . (Example screenshot of an existing Truth Table Generator ) I have the following questions: How should I go about parsing expressions like: ((P => Q) & (Q => R)) => (P => R) Should I use a parser generator like ANTLr or YACC, or use straight regular expressions? Once I have the expression parsed, how should I go about generating the truth table? Each section of the expression needs to be divided up into its smallest components and re-built from the left side of the table

How do I parse indents and dedents with pyparsing?

為{幸葍}努か 提交于 2019-11-30 02:16:37
Here is a subset of the Python grammar: single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE stmt: simple_stmt | compound_stmt simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE small_stmt: pass_stmt pass_stmt: 'pass' compound_stmt: if_stmt if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT (You can read the full grammar in the Python SVN repository: http://svn.python.org/.../Grammar ) I am trying to use this grammar to generate a parser for Python, in Python. What I am having trouble with is how to express the

Can parser combinators be made efficient?

隐身守侯 提交于 2019-11-29 19:06:15
Around 6 years ago, I benchmarked my own parser combinators in OCaml and found that they were ~5× slower than the parser generators on offer at the time. I recently revisited this subject and benchmarked Haskell's Parsec vs a simple hand-rolled precedence climbing parser written in F# and was surprised to find the F# to be 25× faster than the Haskell. Here's the Haskell code I used to read a large mathematical expression from file, parse and evaluate it: import Control.Applicative import Text.Parsec hiding ((<|>)) expr = chainl1 term ((+) <$ char '+' <|> (-) <$ char '-') term = chainl1 fact ((

Resolve conflict in bison grammar with space separated expression lists + if/then/else

狂风中的少年 提交于 2019-11-29 18:07:10
I have the following yacc/bison/happy grammar: %token if TokenIf then TokenThen else TokenElse true TokenTrue false TokenFalse %left APP %right IF %% Hungry : NoHungry | Hungry NoHungry %prec APP | if Hungry then Hungry else Hungry %prec IF NoHungry : true | false bison -v tells me there are two conflicts in the following situation: State 12 2 Hungry: Hungry . NoHungry 3 | if Hungry then Hungry else Hungry . true shift, and go to state 2 false shift, and go to state 3 true [reduce using rule 3 (Hungry)] false [reduce using rule 3 (Hungry)] $default reduce using rule 3 (Hungry) NoHungry go to