bnf

Syntax error using empty production rule in python PLY(lex/yacc)

萝らか妹 提交于 2021-01-02 03:47:34
问题 The full example is given here: import ply.lex as lex import Property # List of token names. This is always required tokens = [ 'CheckupInformation', 'Introduction', 'Information', 'perfect', 'sick', 'LPAREN', 'RPAREN', 'CHAR', 'NUMBER' ] def t_CheckupInformation(t) : 'CheckupInformation' ; return t def t_Introduction(t) : 'Introduction' ; return t def t_Information(t) : 'Information' ; return t def t_perfect(t): 'perfect'; return t def t_sick(t) : 'sick'; return t t_LPAREN = r'\(' t_RPAREN =

Recursive descent: infix to postfix conversion repeating operators

ε祈祈猫儿з 提交于 2020-06-13 11:45:49
问题 We recently learned about converting infix to postfix using stacks during our programming course at uni. And I have meaning to write my parser for a while, so I decided to it using recursive descent. I am following along with this: Parsing Expressions by Recursive Descent Theodore Norvell . Here is the grammar he uses: E --> P {B P} P --> v | "(" E ")" | U P B --> "+" | "-" | "*" | "/" | "^" U --> "-" | "+" I have attempted at implementing this in C and it works. However If I give it the

Can I improve this GOLD Parser Grammar?

有些话、适合烂在心里 提交于 2020-02-05 05:43:05
问题 I have to parse a file that looks like this: versioninfo { "editorversion" "400" "editorbuild" "4715" } visgroups { } world { "id" "1" "mapversion" "525" "classname" "worldspawn" solid { "id" "2" side { "id" "1" "plane" "(-544 -400 0) (-544 -240 0) (-272 -240 0)" } side { "id" "2" "plane" "(-544 -240 -16) (-544 -400 -16) (-272 -400 -16)" } } } I have a parser written from scratch, but it has a few bugs that I can't track down and I imagine it'll be difficult to maintain if the format changes

AS3 Grammar: Most accurate

房东的猫 提交于 2020-01-31 05:12:19
问题 I'm looking for an accurate AS3 grammar (format in not an issue, but I presume ANTLR will feature the most) to use for a practice grammar I'm making. What is the most accurate grammar available for AS3? 回答1: I think this one is pretty accurate if you are looking for an ANTLR grammar: AS3.g This grammar has been originally developed a couple of years ago by Martin Schnable and then extended for the Meta-AS project. There are of course other ActionScript 3 parsers available as well, but they do

Can a BNF handle forward consumption?

梦想的初衷 提交于 2020-01-14 11:52:53
问题 Recently I've discovered the python module pyparsing , a wonderful tool for parsing data by writing the grammar , not the parser. I'm new to the idea of context-free grammars, so please correct any false assumptions in this question. Pyparsing can implement a BNF (Backus–Naur Form) context-free grammar. This grammar can be recursive, but can it have a forward look-ahead? I've been wondering about the answer to this since I stumbled across this question. Let me give you a concrete example.

What are Context-Free Grammars and Backus Naur Form?

廉价感情. 提交于 2020-01-13 13:08:52
问题 Can someone please explain in layman's terms: what a context-free grammar is? what Backus Naur Form is? How to use this notation? How to do string derivation? How to describe language syntax? 回答1: A context-free grammar (CFG) G is a quadruple (V, Σ, R, S) where V: a set of non-terminal symbols Σ: a set of terminals (V ∩ Σ = Ǿ) R: a set of rules (R: V → (V U Σ)*) S: a start symbol Example of CFG: V = {q, f,} Σ = {0, 1} R = {q → 11q, q → 00f, f → 11f, f → ε} S=q (R= {q → 11q | 00f, f → 11f | ε

Is there a BNF with arguments for non-terminal symbols?

会有一股神秘感。 提交于 2019-12-23 13:05:36
问题 In working with Prolog DCG to parse input it is nice to have an accompaning BNF of the grammar. For example: BNF <Sentence> ::= <Noun_phrase> <Verb_phrase> <Noun_phrase> ::= <Determiner> <Noun> <Verb_phrase> ::= <Verb> <Phrase> <Determiner> ::= a <Determiner> ::= the <Noun> ::= cat <Noun> ::= mouse <Verb> ::= scares <Verb> ::= hates as Prolog DCG sentence --> noun_phrase, verb_phrase. verb_phrase --> verb, noun_phrase. noun_phrase --> determiner, noun. determiner --> [a]. determiner --> [the]

How to generate random programs from BNF

这一生的挚爱 提交于 2019-12-23 11:58:22
问题 I know my question sounds a little vague, but I could not find any tutorials online. I am not asking for an answer, but for more of an explanation. An example of the BNF: <prog> ::= “int main() { <stat_list> return 0; }” <stat_list> ::= <stat> | <stat_list> <stat> <stat> ::= <cmpd_stat> | <if_stat> | <iter_stat> | <assgn_stat> | <decl_stat> <cmpd_stat> ::= { <stat_list> } <if_stat> ::= if ( <exp> ) <stat> | if ( <exp> ) <cmpd_stat> | if ( <exp> ) <stat> else <stat> | if ( <exp> ) <cmpd_stat>

How to build parse tree?

笑着哭i 提交于 2019-12-22 14:32:23
问题 Have found C++ BNF and there next lines selection-statement: if ( condition ) statement if ( condition ) statement else statement Now trying to write parser. Need to build parse tree. On input i have BNF and source file. But i'm stucked in how i can point my parser what if condition evaluated to true, then it need to execute first statement otherwise else block? Thanks. 回答1: Conditional statements have a simple recursive structure. The corresponding recursive descent parser has a similarly

How to build parse tree?

青春壹個敷衍的年華 提交于 2019-12-22 14:30:13
问题 Have found C++ BNF and there next lines selection-statement: if ( condition ) statement if ( condition ) statement else statement Now trying to write parser. Need to build parse tree. On input i have BNF and source file. But i'm stucked in how i can point my parser what if condition evaluated to true, then it need to execute first statement otherwise else block? Thanks. 回答1: Conditional statements have a simple recursive structure. The corresponding recursive descent parser has a similarly