[antlr-interest] My first tree walker / Parser
Simon Manschitz
simon.werbung at gmx.de
Fri Dec 10 12:17:02 PST 2010
Hi,
thanks, that's a strange error. I am using the Eclipse IDE and my .g files and the token files are in my project folder. I had another token file (I don't know why) in my src folder where my generated java files are. I deleted that file and now it works.
Now i found another error with the addition in my parser. An input like:
function [output] = test2(input)
output = 2*5/3-1;
end
works fine for example. output = 2 + 3 works, too. But when there is no white space between the numbers he complains about a no viable alternative at input 2+3 error.
I checked the interpreter and he seems to recognize 2+ 3 as atom (and not as add_or_sub_expr) and doesn't recognize 2+3 (* - / etc all work fine) at all.
Can somebody help me finding this error? I thought it has something to do with the definition of a lexer rule like REAL_NUMBER but i can't see any mistakes.
The grammar file is quite large so i uploaded it to: http://www.breuberg.de/vereine/tsv-neustadt/Matlab.g
Greetings, Simon.
Am 10.12.2010 18:04, schrieb Terence Parr:
> sounds like a token type mismatch...make sure FUNCTION is same in all grammars
> T
> On Dec 10, 2010, at 5:56 AM, Simon Manschitz wrote:
>
>> Hi,
>>
>> i am trying to walk over a tree with this forum (tree.toTreeString-Method):
>>
>> (function (OUTPUT output) (NAME test2) (INPUT input) (= output (- 4 input)))
>>
>> My tree walker looks like this:
>>
>> tree grammar MatlabTreeWalker;
>>
>> options {
>> language = Java;
>> tokenVocab = Matlab;
>> ASTLabelType = CommonTree;
>> }
>>
>> walk: ^(FUNCTION
>> function_output
>> function_name
>> function_input
>> expression);
>>
>> function_output: ^(OUTPUT IDENT);
>> function_name: ^(NAME IDENT);
>> function_input: ^(INPUT IDENT);
>>
>> expression:
>> ^('=' expression expression) { System.out.println("t1"); }
>> | ^(MINUS o1=expression o2=expression) { System.out.println("t2"); }
>> | IDENT { System.out.println("t3"); }
>> | REAL_NUMBER { System.out.println("t4"); };
>>
>> But i always receive this error: MatlabTreeWalker.g: node from line 1:0
>> mismatched tree node: function expecting FUNCTION. Has anyone an idea
>> why i get this error? FUNCTION is a lexer rule FUNCTION: 'function'; I
>> think he has problems to find the (OUTPUT IDENT) but i have no idea why?
>> Can somebody help me?
>>
>> Bye, Simon.
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
--
Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief!
Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail
More information about the antlr-interest
mailing list