grammar

Error when adapting a class with BOOST_FUSION_ADAPT_ADT

三世轮回 提交于 2019-12-01 05:29:19
问题 I've the following class: #ifndef WFRACTAL_FRACTAL_METADATA_H_ #define WFRACTAL_FRACTAL_METADATA_H_ #include <string> namespace WFractal { namespace Fractal { class Metadata { public: void setAuthorName(const std::string &name); void setAuthorEMail(const std::string &email); void setBriefDescription(const std::string &brief); void setCompleteDescription(const std::string &description); std::string getAuthorName() const; std::string getAuthorEMail() const; std::string getBriefDescription()

Using ANTLR Parser and Lexer Separatly

孤街醉人 提交于 2019-12-01 04:12:51
I used ANTLR version 4 for creating compiler.First Phase was the Lexer part. I created "CompilerLexer.g4" file and putted lexer rules in it.It works fine. CompilerLexer.g4: lexer grammar CompilerLexer; INT : 'int' ; //1 FLOAT : 'float' ; //2 BEGIN : 'begin' ; //3 END : 'end' ; //4 To : 'to' ; //5 NEXT : 'next' ; //6 REAL : 'real' ; //7 BOOLEAN : 'bool' ; //8 . . . NOTEQUAL : '!=' ; //46 AND : '&&' ; //47 OR : '||' ; //48 POW : '^' ; //49 ID : [a-zA-Z]+ ; //50 WS : ' ' -> channel(HIDDEN) //50 ; Now it is time for phase 2 which is the parser.I created "CompilerParser.g4" file and putted grammars

Help with left factoring a grammar to remove left recursion

匆匆过客 提交于 2019-12-01 04:01:49
I have a small custom scripting language, and I am trying to update it to allow boolean expressions such as a > 2 and a > 2 and (b < 3 or c > 5) . It's the parenthetical expressions that I am having trouble with here. Here is a (edited since the original post based on the answer from @Bart Kiers) full grammar that exhibits the problem. This is a pared-down version of my actual grammar, but the problem occurs here too. grammar test; options { language = 'JavaScript'; output = AST; } statement : value_assignment_statement EOF ; value_assignment_statement : IDENT '=' expression ; value_expression

Parsing of optionals with PEG (Grako) falling short?

北战南征 提交于 2019-12-01 03:52:54
问题 My colleague PaulS asked me the following: I'm writing a parser for an existing language (SystemVerilog - an IEEE standard), and the specification has a rule in it that is similar in structure to this: cover_point = [[data_type] identifier ':' ] 'coverpoint' identifier ';' ; data_type = 'int' | 'float' | identifier ; identifier = ?/\w+/? ; The problem is that when parsing the following legal string: anIdentifier: coverpoint another_identifier; anIdentifier matches with data_type (via its

Parsing numbers with multiple digits in Prolog

坚强是说给别人听的谎言 提交于 2019-12-01 03:40:47
I have the following simple expression parser: expr(+(T,E))-->term(T),"+",expr(E). expr(T)-->term(T). term(*(F,T))-->factor(F),"*",term(T). term(F)-->factor(F). factor(N)-->nat(N). factor(E)-->"(",expr(E),")". nat(0)-->"0". nat(1)-->"1". nat(2)-->"2". nat(3)-->"3". nat(4)-->"4". nat(5)-->"5". nat(6)-->"6". nat(7)-->"7". nat(8)-->"8". nat(9)-->"9". However this only supports 1-digit numbers. How can I parse numbers with multiple digits in this case? Use accumulator variables, and pass those in recursive calls. In the following, A and A1 are the accumulator. digit(0) --> "0". digit(1) --> "1". %

What is the easiest way of telling whether a BNF grammar is ambiguous or not?

怎甘沉沦 提交于 2019-12-01 03:10:35
Namely, is there a tool out there that will automatically show the full language for a given grammar, including highlighting ambiguities (if any)? There might be some peculiarity about BNF-style grammars, but in general, deciding whether a given context-free grammar (such as BNF) is ambiguous is not possible. In short, there does not exist a tool because in general, that tool is mathematically impossible. There might be some special cases that could work for you, though. In general, no. But as a practical approach, what you can do, is given a grammar, is for each rule, to enumerate possible

Is sizeof(int()) a legal expression?

房东的猫 提交于 2019-12-01 02:16:59
This question is inspired by Is sizeof(void()) a legal expression? but with an important difference as explained below. The expression in question is: sizeof( int() ) In the C++ grammar there appears: unary-expression: sizeof unary-expression sizeof ( type-id ) however, ( int() ) can match both of these cases with different meanings: As a unary-expression , it is a value-initialized int prvalue, surrounded in redundant parentheses As a type-id , it is the type of a function with no parameters returning int . In the semantic constraints for sizeof , i.e. C++14 [expr.sizeof]/1, it explains that

Why is the separator in a TypeScript TypeMemberList semicolon as opposed to comma?

喜欢而已 提交于 2019-12-01 02:05:24
This is a typescript interface: interface A { l: { x: string; y:number } } But this (similar thing) produces an error: interface A { l: { x: string, y:number } } // => Error: ';' expected. On p.37 of the spec: http://www.typescriptlang.org/Content/TypeScript%20Language%20Specification.pdf I see that indeed it is specified that a ; should appear there, but coming from JavaScript the semicolon in the middle of the object-literal-ish thing looks wrong. Was this decision made to avoid ambiguity in the parser, or for some other reason? As of TypeScript 1.6 or so, you can now use either , or ; as a

Help with left factoring a grammar to remove left recursion

倖福魔咒の 提交于 2019-12-01 01:57:23
问题 I have a small custom scripting language, and I am trying to update it to allow boolean expressions such as a > 2 and a > 2 and (b < 3 or c > 5) . It's the parenthetical expressions that I am having trouble with here. Here is a (edited since the original post based on the answer from @Bart Kiers) full grammar that exhibits the problem. This is a pared-down version of my actual grammar, but the problem occurs here too. grammar test; options { language = 'JavaScript'; output = AST; } statement

Keyword or keyphrase spotting with Sphinx4

廉价感情. 提交于 2019-11-30 23:53:29
I am currently trying to make my java code (using eclipse) perform some function if a certain thing is said. I am using the Sphinx4 libraries and this is what I currently have: What I would like it to do is at the line where it says: IF (TRUE) someFunction(); is to run the function if my speech is Hello Computer, Hello Jarvis, Good Morning Computer, or Good Morning Jarvis. Or in other words, run the function if the speech matches the "public < greet >" line of code in the .gram file. Even more specific, return "greet" if my speech corresponds with that grammar rule. I am sorry if this doesnt