parser-generator

What parser generator does CPython use?

旧巷老猫 提交于 2020-01-24 03:24:25
问题 I was reading this page in the documentation, and noticed that it says This is the full Python grammar, as it is read by the parser generator and used to parse Python source files However, I'm having difficulty finding out what parser generator CPython uses. So what parser generator does CPython use? Are there other parser generators that would take the grammar on that page without any modifications? 回答1: Python is open-source, so you can inspect the source code... In the Python source

Define parsers parameterized with sub-parsers in Boost Spirit

爱⌒轻易说出口 提交于 2020-01-11 05:22:06
问题 I would like to convert some old hand-written parsing code to Boost Spirit and learn (more of) spirit in the process. The old code uses streams and templates to parse definitions for some data-types and some containers. Some typical formats: VECTOR[number_of_items,(item_1, item_2 .... item_n)] PAIR(p1, p2) RECT[(left,top)-(right,bottom)] Point( x, y ) Size( x, y ) The parsing functions are templates with the type of the items as template parameter and use streams as input, e.g. template<class

ANTLR: How to skip multiline comments

丶灬走出姿态 提交于 2020-01-04 04:12:19
问题 Given the following lexer: lexer grammar CodeTableLexer; @header { package ch.bsource.ice.parsers; } CodeTabHeader : OBracket Code ' ' Table ' ' Version CBracket; CodeTable : Code ' '* Table; EndCodeTable : 'end' ' '* Code ' '* Table; Code : 'code'; Table : 'table'; Version : '1.0'; Row : 'row'; Tabdef : 'tabdef'; Override : 'override' | 'no_override'; Obsolete : 'obsolete'; Substitute : 'substitute'; Status : 'activ' | 'inactive'; Pkg : 'include_pkg' | 'exclude_pkg'; Ddic : 'include_ddic' |

ANTLR parser hanging at proxy.handshake call

元气小坏坏 提交于 2020-01-02 05:14:18
问题 I am attempting to get a basic ECMAScript parser working, and found a complete ANTLR grammar for ECMAScript 3, which appears to compile ok and produces the appropriate Lexer/Parser/Walker Java files. (Running inside ANTLR IDE plugin for Eclipse 3.5) However, when actually trying to use it with some simple test code (following guide on ANTLR wiki), it just hangs when trying to create the parser: CharStream MyChars = new ANTLRFileStream(FileName); // FileName is valid ES3Lexer MyLexer = new

ANTLR parser hanging at proxy.handshake call

我只是一个虾纸丫 提交于 2020-01-02 05:14:05
问题 I am attempting to get a basic ECMAScript parser working, and found a complete ANTLR grammar for ECMAScript 3, which appears to compile ok and produces the appropriate Lexer/Parser/Walker Java files. (Running inside ANTLR IDE plugin for Eclipse 3.5) However, when actually trying to use it with some simple test code (following guide on ANTLR wiki), it just hangs when trying to create the parser: CharStream MyChars = new ANTLRFileStream(FileName); // FileName is valid ES3Lexer MyLexer = new

ANTLR parsing MismatchedTokenException

拜拜、爱过 提交于 2019-12-31 04:37:07
问题 I'm trying to write a simple parser for an even simpler language that I'm writing. It's composed of postfix expressions. As of now, I'm having issues with the parser. When I run it on the input 2 2 * test >> I get a MismatchedTokenException. Also, how would I go about implementing a recursive postfix parser? Here's my code: grammar star; options { language=Python; output=AST; ASTLabelType=CommonTree; } tokens {DECL;} //start // : decl ; //decl // : type ID -> ^(DECL type ID) // ; program :

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

对着背影说爱祢 提交于 2019-12-29 09:34:47
问题 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

Negating inside lexer- and parser rules

此生再无相见时 提交于 2019-12-28 02:55:26
问题 How can the negation meta-character, ~ , be used in ANTLR's lexer- and parser rules? 回答1: Negating can occur inside lexer and parser rules. Inside lexer rules you can negate characters, and inside parser rules you can negate tokens (lexer rules). But both lexer- and parser rules can only negate either single characters, or single tokens, respectively. A couple of examples: lexer rules To match one or more characters except lowercase ascii letters, you can do: NO_LOWERCASE : ~('a'..'z')+ ;

Bison - recover from If Else error

大兔子大兔子 提交于 2019-12-25 02:56:10
问题 I'm trying to recover from an error in an If-Else statement. In my grammar an If is always followed by an Else. statement: OBRACES statements CBRACES | IF OPAR exp CPAR statement ELSE statement | IF OPAR exp CPAR statement error '\n' { yyerrok; yyclearin;} ; The error found is in the commented else in the last lines: public boolean Equal(Element other){ if (!this.Compare(aux01,Age)) ret_val = false ; //else //nt = 0 ; } error: syntax error, unexpected CBRACES, expecting ELSE -> } @ line 29 It

Expression evaluator for C#/Python/Ruby

我的未来我决定 提交于 2019-12-24 09:52:34
问题 We have semi-complicated expressions in the format: "25 + [Variable1] > [Variable2]" We need an expression evaluator to parse the expression and use a callback to ask for the variable values and work out the overall result of the expression. It has to be a callback as there are thousands of variables. We need the usual math operators but also things like "if" etc. The richer the language the better. We can use any language we want. Anyone have any suggestions? 回答1: Check out NCalc. It's .NET