March 01, 1999
Compiler Construction with ANTLR and Java
Compiler Construction with ANTLR and JavaBy Gary L. SchapsDr. Dobb's Journal March 1999
// cycle names
cycleNames
// init-action
{CycleNames cycleN = null; int startLine=LT(1).getLine();}
// rule
: "CYCLE_NAMES" ASSIGN LCURLY
{cycleN = new CycleNames();}
// rest of rule
cycleSet[cycleN] (COMMA cycleSet[cycleN])* RCURLY SEMI
// semantic action
{
try{
PBIBuilder.registerCycleNames(cycleN);
}catch (IllegalStateException ex){
PBIBuilder.foundBadCode();
System.err.println("Error: line(" + (startLine) +
"), " + ex.getMessage());
}
}
;
Example 4: Parsing an element of the language.
Copyright © 1999, Dr. Dobb's Journal
|
|
||||||||||||||||||||||||||||
|
|