antlr

Skipping unmatched input in Antlr

[亡魂溺海] 提交于 2019-12-13 02:11:20
问题 Is there a way to specify in a grammar that I want to skip all input that doesnt match any of the rules (that would otherwise throw a recognition error)? 回答1: Yes. Implementation depends on where you need/want to do the skipping. In the lexer, a last rule like: Unknown : . -> skip ; // or -> channel(HIDDEN) ; will consume any otherwise unmatched input characters yet keep them from being tokenized and considered by the parser. You do want to match a single character at a time so that at every

Extraneous input '-' expecting in ANTLR4

烂漫一生 提交于 2019-12-12 23:18:34
问题 Could you please tell me what could be the problem? It's expect {<EOF>, '(', NUMBER, VARIABLE} , but if i insert this rules after - , i got same error. grammar Grammar; @header { package parser; } program: line* EOF ; line: (expression | assignment) ('\n' | EOF); assignment : VARIABLE '=' expression ; expression : '(' expression ')' #parenthesisExpression | left=expression OP1 right=expression #firstPriorityExpression | left=expression OP2 right=expression #secondPriorityExpression | number

ANTLR - Boolean satisfiabilty

时光总嘲笑我的痴心妄想 提交于 2019-12-12 22:43:02
问题 I have a ANTLR expression parser which can evaluate expressions of the form ( A & ( B | C ) ) using the generated visitor. A , B and C can take any of the 2 values true or false . However I am faced with a challenge of finding all combinations of A,B and C for which the expression is true. I tried to solve this by the following method. Evaluate the expression for the 3 variables taking true and false each This comes to 8 combinations since 2 ^ 3 is 8 I evaluate giving values like 000, 001,

ANTLR: error recovery and reporting

[亡魂溺海] 提交于 2019-12-12 20:51:48
问题 i have problems to recovery and reposting error with ANTLR v3. i follow this link http://www.antlr.org/blog/antlr3/error.handling.tml but i don't have that solutions. i want to make some reporting and recovery for example in the source program like this : student input code : FOR(int a=0;a<10;a++){ b=b*a; } and the program will report like this: Program : "are you meant the keyword FOR is for?" student answer:"yes" after that, the system recovery and modified the source code automatically.

antlr c# errors when integrating into VS2008

心已入冬 提交于 2019-12-12 18:23:38
问题 I am following the tutorial at: http://www.antlr.org/wiki/pages/viewpage.action?pageId=557075 When I get to step 11, compile with VS I am getting the following: Error The type or namespace name 'AstParserRuleReturnScope' could not be found Error The type or namespace name 'GrammarRule' could not be found Error The type or namespace name 'GrammarRuleAttribute' could not be found etc. Any tips from anyone? There is little to no documentation to help me here. Thanks! 回答1: Use ANTLRWorks 1.4 to

ANTLR Propositional Logic Evaluator

元气小坏坏 提交于 2019-12-12 18:04:58
问题 I'm trying to create a grammar in ANTLR that evaluates propositional logic formulas. So for the input (1 & 0) | 1 , it should return true . I have constructed the following: code returns[boolean value] : formula EOF {$value = $formula.value;} ; formula returns [boolean value] : equiv {$value = $equiv.value;} ; equiv returns [boolean value] : a=implies {$value = $a.value;} ( '#' b=implies {$value = $value == $b.value;} )* ; implies returns [boolean value] : a=or {$value = $a.value;} ( '>' b=or

Remove (absolute) paths in ANTLR generated java classes:

陌路散爱 提交于 2019-12-12 15:20:19
问题 I am using ANTLRWorks 1.4.3 together with ANTLR 3.4 to generate a Java-based parser and lexer from a grammar file. The generated .java -files contain strings like C:\\Users\\[path to the eclipse project]\\src\\some\\package\\name\\MyGrammar.g This absolute path is used as return string e.g. in method getGrammarFileName() of lexer and parser, and throughout the both files various times as comment. I see following disadvantages: If somebody else with different paths in his development

ANTLR: empty condition not working

落爺英雄遲暮 提交于 2019-12-12 12:27:10
问题 I want to be able to parse int [] or int tokens. Consider the following grammar: TYPE : 'int' AFTERINT; AFTERINT: '[' ']'; Of course it works, but only for int [] . To make it work for int too, I changed AFTERINT to this (added an empty condition': AFTERINT: '[' ']' | |; But now I get this warning and error: [13:34:08] warning(200): MiniJava.g:5:9: Decision can match input such as "" using multiple alternatives: 2, 3 As a result, alternative(s) 3 were disabled for that input [13:34:08] error

Are there any simple languages implemented using ANTLR or similar?

帅比萌擦擦* 提交于 2019-12-12 10:41:46
问题 I'm trying to build a simple interpreted language for learning purposes. I've read countless theory and tutorials on ANTLR and JavaCC, but I can't figure out how to actually make it do something useful. I learn best by "taking something apart and putting it back together again", so, are there any working examples of simple languages implemented with the help of tools such as ANTLR, or similar? Something like the following might be nice: x = 1 if x == 1 print "true" 回答1: [shameless plug] Why