Sunday 15 May 2011

java - JavaCC recognise token within token -



java - JavaCC recognise token within token -

i'm having problem javacc project. i'm trying recognise variable declaration has possible "variable" prefix, kind , name of variable (id). parser recognise first word kind , not go on rest of line.

it says:

exception in thread "main" parseexception: encountered " <kind> "char "" @ line 2, column 9. expecting 1 of: <variable> ...

here's how tokens declared

token : { <start: "start"> {debugstream.println("start");} | <end: "end"> {debugstream.println("end");} | <variable: ("variable" <kind> <id>) | (<kind> <id>)> {debugstream.println("variable decl");} | <kind: "integer"|"real"|"logic"|"char"|"text"> {debugstream.println("kind");} | <id: (["a"-"z","_"])+> {debugstream.println("id");} }

i've tried set kind , id special_tokens, parser goes without errors, don't recognise variable declaration too.

edit:

here's input string

start char sex integer num end

if want "char sex" tokenize 1 token of kind variable need allow spaces in variables. e.g.

<variable: ("variable" (" ")+ <kind> (" ")+ <id>) | (<kind> (" ")+ <id>)>

however, i'd suggest consider doing following: alter variable rule to

<variable: "variable">

write new nonterminal

void variable() : {} { <variable> <kind> <id> | <kind> <id> }

java token javacc

No comments:

Post a Comment