antlrworks

What is wrong with this grammar? (ANTLRWorks 1.4)

感情迁移 提交于 2019-12-21 22:15:06
问题 I have the following code written in ANTLRWorks 1.4 grammar hmm; s : (put_a_in_b)|(put_out_a)|(drop_kick)|(drop_a)|(put_on_a); put_a_in_b : (PUT_SYN)(ID)(IN_SYN)(ID); put_out_a : (PUT2_SYN)(OUT_SYN)(ID) | (E1)(ID); drop_kick : ('drop')('kick')(ID); drop_a : (DROP_SYN)(ID); put_on_a : (E2)(ID); PUT_SYN : 'put' | 'place' | 'drop'; PUT2_SYN : 'put' | 'douse'; IN_SYN : 'in' | 'into' | 'inside' | 'within'; OUT_SYN : 'out'; E1 : 'extinguish'|'douse'; DROP_SYN : 'drop' | 'throw' | 'relinquish'; WS :

Parsing with incomplete grammars

点点圈 提交于 2019-12-21 17:14:43
问题 Are there any common solutions how to use incomplete grammars? In my case I just want to detect methods in Delphi (Pascal)-files, that means procedures and functions . The following first attempt is working methods : ( procedure | function | . )+ ; but is that a solution at all? Are there any better solutions? Is it possible to stop parsing with an action (e. g. after detecting implementation ). Does it make sense to use a preprocessor? And when yes - how? 回答1: If you're only looking for

Parsing Newlines, EOF as End-of-Statement Marker with ANTLR3

落花浮王杯 提交于 2019-12-13 13:30:24
问题 My question is in regards to running the following grammar in ANTLRWorks: INT :('0'..'9')+; SEMICOLON: ';'; NEWLINE: ('\r\n'|'\n'|'\r'); STMTEND: (SEMICOLON (NEWLINE)*|NEWLINE+); statement : STMTEND | INT STMTEND ; program: statement+; I get the following results with the following input (with program as the start rule), regardless of which newline NL (CR/LF/CRLF) or integer I choose: "; NL " or "32; NL " parses without error. ";" or "45;" (without newlines) result in EarlyExitException. " NL

ANTLRWorks 2.1: generated Lexer+Parser in Eclipse causing UUID exception

我只是一个虾纸丫 提交于 2019-12-13 01:15:18
问题 I'm new to ANTLR and ANTLRWorks, so I'm quite puzzled by this: I'm using ANTLRWorks 2.1 for grammar creation and subsequent creation of the lexer and parser (Java target). I have then created a small Eclipse project and imported the ANTLR4 jars from ANTLRWorks to manually call the lexer and parser as described in the ANTLR book examples. When running the application I get the following exception: Caused by: java.lang.UnsupportedOperationException: java.io.InvalidClassException: org.antlr.v4

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

Why does Antlr not generate a lexer java file?

时间秒杀一切 提交于 2019-12-12 03:09:28
问题 Antlr3 does not generate Mylexer.java. I use AntlrWorks... when I have grammar starting like grammar mylexer; It does generate myParser.java It looks like a simple thing.. I wonder what may be the reason.. and the solution... I get no error message. 回答1: I found a way. AntlrWorks 1.4 seems to have a bug. When I pressed ctrl+shift+G to generate it did not give an error message (in fact, I got that compilation was ok) and generated a parser file only. The cursor was not on the first line of the

move to a new state after cosuming tokens in antlr4

自古美人都是妖i 提交于 2019-12-11 07:44:49
问题 i have following grammar root : sql_statements EOF | EOF ; sql_statements :( sql_statement )+ ; sql_statement : ddl_statement semicolon ; ddl_statement : alter_statement ; This is a initial snapshot of my grammar i have following test case aleter table user;alter table group_user; first statement has error hence i am getting error for both statements under sql_statements rule Failed to parse at line 1:1 due to mismatched input 'aleter' expecting ALTER Now i want to use Defaulterrorhandler

Antlr AST generating (possible) madness

拜拜、爱过 提交于 2019-12-11 06:57:06
问题 Is the following even possible? I want to "reverse" the input given to antlr and make each token a child of the previous one. So, for the input (Assume each token is separated by the '.' char) : Stack.Overflow.Horse I would like my grammar to produce the following AST: Horse |---Overflow |---Stack So far, I've managed to reverse the nodes, but I'm unable to make them children of each other: function : ID PERIOD function -> function ID | ID ; ID : 'a'..'z'* ; 回答1: I don't think there's an easy

ANTLR/Grammar issue: calculator language

旧街凉风 提交于 2019-12-11 05:07:46
问题 I'm attempting to create a boolean expression language/grammar for a personal project. The user will be able to write a string in a Java-like syntax, with provision for variables, which will be evaluated at a later time when the variables have been initialised. Rain For example, a user might enter the string @FOO+7 > 4*(5+@BAR); Later, when the variable FOO is initialised and equal to 6, and BAR is equal to 1, the expression evaluates to 13>24 and thus returns false. I'm using ANTLRworks to

How to get rid of the following multiple alternatives warnings in my ANTLR3 grammar?

天大地大妈咪最大 提交于 2019-12-10 21:21:26
问题 [11:45:19] warning(200): mygrammar.g:14:57: Decision can match input such as "','" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input [11:45:19] warning(200): C:\Users\Jarrod Roberson\mygrammar.g:14:57: Decision can match input such as "','" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input I want to be able to nest functions inside other functions. myfunction(x) -> sqr(a) -> a * a, y -> sqr(x). here is the