grammar

How [“03C0”] match <Ada Reference Manual>'s grammar in Annex P?

时间秒杀一切 提交于 2019-12-10 17:26:30
问题 I'm writing a tool to parse Ada source file with the grammar provided in 2005 Annex P. With following piece of code, I know ["03C0"] stands for "greek letter Pi", but is it a legal variable name? 01 package Ada.Numerics is 02 Pi : constant := 3.14159_26535_89793_23846_26433_83279_50288_41971_69399_37511; 03 ["03C0"] : constant := Pi; 04 e : constant := 2.71828_18284_59045_23536_02874_71352_66249_77572_47093_69996; 05 end Ada.Numerics; When using the grammar to parse line 03, I currently come

Extended Backus–Naur Form order of operations

笑着哭i 提交于 2019-12-10 15:44:03
问题 I am creating a formal spec for a very simple rule language, very simple. I want to use EBNF as this is a standard but I can't figure out how to specify order of operations. Here is the specification so far. rule = statement, { (‘AND’|’OR’), statement}; variable = ‘$’,alphabetic character, {alphabetic character | digit}; statement = variable, [ ‘count’,[white space ],’>’,[white space],number ]; alphabetic character = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M"

Token recognition error: antlr

强颜欢笑 提交于 2019-12-10 15:25:39
问题 I have an ANTLR 4 grammar: grammar Test; start : NonZeroDigit '.' Digit Digit? EOF ; DOT : '.' ; PLUS : '+' ; MINUS : '-' ; COLON : ':' ; COMMA : ',' ; QUOTE : '\"' ; EQUALS : '=' ; SEMICOLON : ';' ; UNDERLINE : '_' ; BACKSLASH : '\\' ; SINGLEQUOTE : '\'' ; RESULT_TYPE_NONE : 'NONE' ; RESULT_TYPE_RESULT : 'RESULT' ; RESULT_TYPE_RESULT_SET : 'RESULT_SET' ; TYPE_INT : 'Int' ; TYPE_LONG : 'Long' ; TYPE_BOOL : 'Bool' ; TYPE_DATE : 'Date' ; TYPE_DOUBLE : 'Double' ; TYPE_STRING : 'String' ; TYPE

Writing parser rules sensitive to whitespace while skipping WS from the lexer

本秂侑毒 提交于 2019-12-10 14:14:38
问题 I am having some troubles in handling whitespace. In the following excerpt of a grammar, I set up the lexer so that the parser skips whitespace: ENTITY_VAR : 'user' | 'resource' ; INT : DIGIT+ | '-' DIGIT+ ; ID : LETTER (LETTER | DIGIT | SPECIAL)* ; ENTITY_ID : '__' ENTITY_VAR ('_w_' ID)?; NEWLINE : '\r'? '\n'; WS : [ \t\r\n]+ -> skip; // skip spaces, tabs, newlines fragment LETTER : [a-zA-Z]; fragment DIGIT : [0-9]; fragment SPECIAL : ('_' | '#' ); The problem is, I would like to match

Any PEG parser capable to handle left recursion? [closed]

廉价感情. 提交于 2019-12-10 13:52:28
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Well, I know it's possible to rewrite the grammar to eliminate left recursion. But this is a very boring process, and sometimes it's very nontrivial to keep correct associativity. Is there any parser capable to handle properly grammars with left recursion? 来源: https://stackoverflow.com/questions/4397039/any-peg

Question - formal language in prolog

这一生的挚爱 提交于 2019-12-10 13:35:05
问题 I am trying to build a DCG which recognizes all lists which match this form : a^n b^2m c^2m d^n . I have written up the following rules: s --> []. s --> ad. ad --> a, ad, d. ad --> bc. bc --> b, b, bc, c, c. bc --> []. a --> [a]. b --> [b]. c --> [c]. d --> [d]. When I try to evaluate a string with those specifications, like the list [a,b,b,c,c,d] , it works. But when I try to evaluate the query phrase(s, X) so that I can see all the possible strings returned by this grammar, it loops to

ANTLR “Cannot launch the debugger. Time-out waiting to connect to the remote parser.”

爷,独闯天下 提交于 2019-12-10 13:22:13
问题 One of my ANTLR grammars running in AntlrWorks throws: “Cannot launch the debugger. Time-out waiting to connect to the remote parser.” In the past this message usually goes away but this one is persistent. On searching the ANTLR lists (e.g. http://www.antlr.org/pipermail/antlr-interest/2009-June/034659.html) there are hints that the error message is nothing to do with what it seems but could be a grammar error. Has anyone got tips as to how to "reboot" or find the bugs in this situation? 回答1:

Error recovery in an LALR(1) grammar

一世执手 提交于 2019-12-10 11:23:41
问题 I'm using some parser and lexer generating tools (similar to Lex and Bison, but for C#) to generate programs that parse strings into abstract syntax trees that can later be evaluated. I wanted to do error recovery (i.e. report in the produced abstract sentence tree that there are missing tokens and such). I had two approaches in mind to structuring the generated grammars, and I was wondering which approach was better/more flexible/wouldn't have conflicts (the .y and .lex files are generated

How do I best do balanced quoting with Perl's Regexp::Grammars?

戏子无情 提交于 2019-12-10 11:11:42
问题 Using Damian Conway's Regexp::Grammars, I'm trying to match different balanced quoting ( 'foo' , "foo" , but not 'foo" ) mechanisms -- such as parens, quotes, double quotes, and double dollars. This is the code I'm currently using. <token: pair> \'<literal>\'|\"<literal>\"|\$\$<literal>\$\$ <token: literal> [\S]+ This generally works fine and allows me to say something like: <rule: quote> QUOTE <.as>? <pair> My question is how do I reform the output, to exclude the needles notation for the

ANTLR grammar from bison

可紊 提交于 2019-12-10 10:54:27
问题 I'm trying to translate a grammar from bison to ANTLR. The grammar itself is pretty simple in bison but I cannot find a simple way for doing this. Grammar in bison: expr = expr or expr | expr and expr | (expr) Any hints/links/pointers are welcome. Thanks, Iulian 回答1: In ANTLR, you cannot create left recursive rules: a : a b ; tail recursion is fine: a : b a ; For more information on left recursive rules, see ANTLR's Wiki. So, your example could look like: parse : expr+ EOF ; expr : orExpr ;