grammar

How to Prove a Grammar is ambiguous? S -> (S)|SS|()

五迷三道 提交于 2019-12-12 05:14:07
问题 I am rather new to grammars, and was wondering if someone could help me determine using a parse tree how this grammar below is ambiguous? I know that it needs to have two different strings that can be created. S -> (S)|SS|() I can def convert it to chomsky normal form and greibach, but ambiguity is perplexing to me with these. 回答1: The easiest way to prove a grammar ambiguous is to find a sentence with two different parse trees. (Or two different rightmost derivations, which is exactly the

Formal grammar of XML

陌路散爱 提交于 2019-12-12 05:12:16
问题 Im trying to build small parser for XML files in C. I know, i could find some finished solutions but, i need just some basic stuff for embedded project. I`m trying to create grammar for describing XML without attributes, just tags, but it seems it is not working and i was not able to figure out why. Here is the grammar: XML : FIRST_TAG NIZ NIZ : VAL NIZ | eps VAL : START VAL END | STR | eps Here is part of C code that implement this grammar : void check() { getSymbol(); if( sym == FIRST_LINE

Spirit parser segfaults

丶灬走出姿态 提交于 2019-12-12 04:38:14
问题 I'm getting a segfault when I run this. It looks like the debug prints, but when I debug it I just get an endless loop of backtrace. If anyone can help point me in the right direction, I'd appreciate it. I'd also appreciate, if possible any tips/tricks for cleaning up this grammar. Thanks! //code here: /*** *I-EBNF parser * *This defines a grammar for BNF. */ //Speeds up compilation times. //This is a relatively small grammar, this is useful. #define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS

flex&bison shift/reduce conflict

主宰稳场 提交于 2019-12-12 04:12:33
问题 Here are part of my grammar: expr_address : expr_address_category expr_opt { $$ = new ExprAddress($1,*$2);} | axis axis_data { $$ = new ExprAddress($1,*$2);} ; axis_data : expr_opt { $$ = $1;} | sign { if($1 == MINUS) $$ = new IntergerExpr(-1000000000); else if($1 == PLUS) $$ = new IntergerExpr(+1000000000);} ; expr_opt : { $$ = new IntergerExpr(0);} | expr { $$ = $1;} ; expr_address_category : I { $$ = NCAddress_I;} | J { $$ = NCAddress_J;} | K { $$ = NCAddress_K;} ; axis : X { $$ =

Bison warning: Empty rule for typed nonterminal

你离开我真会死。 提交于 2019-12-12 00:26:04
问题 I'm getting a warning I don't really understand from Bison. warning: empty rule for typed non-terminal, and no action it's for each of my non-terminal characters. The part I don't understand is that If I don't give them a type then I get compilation errors stating that all of the $ns are undefined. Here's the grammar section of my bison file. %union { char *sval; } %token <sval> PLUS TIMES LPAREN RPAREN ID %type <sval> s e t f %% s : e { cout << GetNonConstCharStar(std::string("(e ") + $1 + "

Grammar construction in ply - recursion allowed?

▼魔方 西西 提交于 2019-12-11 19:51:31
问题 This has maybe been asked before but I do not know what to search for, really. Suppose I have some string I'd like to build a parser with. I have strings like a OR b , b OR C but also a OR (b AND c) . Now the nested parentheses cause trouble for me and I don't know how to construct the appropriate p_* functions. Is recursion allowed? If so, how? This is what I have thus far: import ply.lex as lex import ply.yacc as yacc # List of token names. This is always required tokens = ( 'VARIABLE', 'OR

how to add a separator in in xtext list?

[亡魂溺海] 提交于 2019-12-11 18:33:54
问题 I have the following grammar fragment: FixtureGroup: name = ID ':' fixtures += [Fixture]* ';'; And in the instance I can type for the above rule the following: FrontLeft: FrontLeft1 FrontLeft2; However, what I like to type is a plus in between: FrontLeft: FrontLeft1 + FrontLeft2; How should I change the grammar to accomplish this? 回答1: the ususal pattern is ':' (fixtures += [Fixture] ('+' fixtures += [Fixture])*)? 来源: https://stackoverflow.com/questions/55929123/how-to-add-a-separator-in-in

Why is antlr4 parsing my sentence into two statements?

…衆ロ難τιáo~ 提交于 2019-12-11 17:14:47
问题 I am writing a little parser for expressions. At the moment I just want it to recognize binary multiplications ( myId * myId ) and C-like dereferenced pointers ( *myId ), plus some assignation statements ( myId *= myId ). The input that makes the parser throw errors is: x *= y; ... on which the parser fails with this message and parse tree: [line 1:1 mismatched input ' *' expecting {';', NEWLINE}] (sourceFile (statement (expressionStatement (expression (monoOperatedExpression

Lemon Parser: This rule can not be reduced

荒凉一梦 提交于 2019-12-11 15:04:37
问题 I'm attempting to write a grammar to parse templating language say jinja2 (or twig at your choose), and I can't successfully parse switch-case statement. Let me show desired syntax: {% switch username %} {% case "Jim" %} I want to say: {% case "Nik" %} Hello man! {% endcase %} {% case "Bob" %} Hi {% default %} Who are you? {% endswitch %} Here endcase just works as break. Worked portion of my grammar file: program ::= template_language(Q) . { status->ret = Q; } template_language(R) ::=

What is a Context Free Grammar?

前提是你 提交于 2019-12-11 14:52:35
问题 Can someone explain to me what a context free grammar is? After looking at the Wikipedia entry and then the Wikipedia entry on formal grammar, I am left utterly and totally befuddled. Would someone be so kind as to explain what these things are? I am wondering this because I wish to investigate parsing, and also on the side, the limitation of a regex engine. I'm not sure if these terms are directly programming related, or if they are related more to linguistics in general. If that is the case