[antlr-interest] What does this error mean? grammer.txt:10:1:
Lexical rule Program defined outside of lexer
Vladimir S.
vs667 at nyu.edu
Wed Feb 22 20:29:46 PST 2006
I get a whole bunch of errors for different rules that all read
something like this:
grammer.txt:10:1: Lexical rule Program defined outside of lexer
What does it mean that lexcial rule "Program" was defined outside of lexer?
Sorry for the noob question.
I have attached the grammer file with this email. It is a grammer file
for a pascal like language.
Thanks!
Vladimir
-------------- next part --------------
//******************************************************** [PARSER]
//********************************************************
//********************************************************
// [X] 0 or 1 = (X)?
// {X} 0 or more instances (X)*
class ParserCore extends Parser;
//========================================================[]
Program:"Program" ID SEMI_COLON (TypeDefinitions)? (VariableDeclarations)? (SubprogramDeclarations)? CompoundStatement;
//========================================================[]
TypeDefinitions : TYPE TypeDefinition SEMI_COLON (TypeDefinition SEMI_COLON )*;
//========================================================[]
VariableDeclarations : VAR VariableDeclaration SEMI_COLON (VariableDeclaration SEMI_COLON ) ;
//========================================================[]
SubprogramDeclarations : ((ProcedureDeclaration | FunctionDeclaration) SEMI_COLON )*;
//========================================================[]
TypeDefinition : ID = Type;
//========================================================[]
VariableDeclaration : IdentifierList COLON Type;
//========================================================[]
ProcedureDeclaration : PROCEDURE ID ( FormalParameterList ) SEMI_COLON ( Block | FORWARD );
//========================================================[]
FunctionDeclaration : FUNCTION ID ( FormalParameterList ) COLON ResultType SEMI_COLON ( Block | FORWARD );
//========================================================[]
FormalParameterList : (IdentifierList COLON Type ( SEMI_COLON IdentifierList : Type )* )?;
//========================================================[]
Block : (VariableDeclarations)? CompoundStatement;
//========================================================[]
CompoundStatement : BEGIN StatementSequence END;
//========================================================[]
StatementSequence : Statement (SEMI_COLON Statement )?;
//========================================================[]
Statement : SimpleStatement | StructuredStatement;
//========================================================[]
SimpleStatement : ( (AssignmentStatement | ProcedureStatement) )?;
//========================================================[]
AssignmentStatement : Variable (":=") Expression;
//========================================================[]
ProcedureStatement : ID ( ActualParameterList );
//========================================================[]
StructuredStatement : CompoundStatement
| IF Expression THEN Statement ( ELSE Statement )?
| WHILE Expression DO Statement
| FOR ID ":=" Expression TO Expression DO Statement
;
//========================================================[]
Type : ID| ARRAY BRAKET_S_OPEN(Constant PERIOD_PERIOD Constant)BRACKET_S_CLOSE OF Type | RECORD FieldList END;
//========================================================[]
ResultType : ID;
//========================================================[]
Fieldlist : ( IdentifierList : Type ( SEMI_COLON IdentifierList COLON Type )* )?;
//========================================================[]
Constant : ( Sign )? INTEGER;
//========================================================[]
Expression : SimpleExpression ( RelationalOp SimpleExpression )*;
//========================================================[]
RelationalOp : OP_LESS| LESS_EQUAL | OP_GREATER| GREATER_EQUAL | NOT_EQUAL | EQUAL;
//========================================================[]
SimpleExpression : (Sign)? Term (AddOp Term )*;
//========================================================[]
AddOp : OP_ADD_SUB| OR;
//========================================================[]
Term : Factor ( MulOp Factor )*;
//========================================================[]
MulOp : OP_MULT|DIV|MOD|AND;
//========================================================[]
Factor : INTEGER | STRING| Variable | FunctionReference
| NOT Factor | PAREN_OPEN Expression PAREN_CLOSE;
//========================================================[]
FunctionReference : ID PAREN_OPEN ActualParameterList PAREN_CLOSE;
//========================================================[]
Variable : ID ComponentSelection;
//========================================================[]
ComponentSelection : BRAKET_S_OPEN ( PERIOD ID ComponentSelection | (Expression)? ComponentSelection ) BRAKET_S_CLOSE;
//========================================================[]
ActualParameterList : BRAKET_S_OPEN Expression (COMMA Expression )* BRAKET_S_CLOSE;
//========================================================[]
IdentifierList : ID (COMMA ID)*;
//========================================================[]
Sign : OP_ADD_SUB;
//******************************************************** LEXER
//********************************************************
//********************************************************
class LexerCore extends Lexer;
options {
k=2;
}
//========================================================[STRING-ALL PRINTABLE CHARS]
STR : BRACKET_C_OPEN (
LETTER
|DIGIT
|'!'
|'#'
|'$'
|'%'
|'&'
|''
|'('
|')'
|OP_MULT
|'/'
|OP_ADD_SUB
|','
|OP_LESS
|OP_GREATER
|'='
|'.'
|':'
|';'
|'@'
|'['
|'\\'
|']'
|'^'
|'_'
|''
|'|'
|'~'
|'?'
|WS
)* BRACKET_C_CLOSE
{ $setType(Token.SKIP); }
;
//========================================================[KEYWORDS]
AND: "and";
BEGIN: "begin";
FORWARD: "forward";
DIV: "div";
DO: "do";
ELSE: "else";
END: "end";
FOR: "for";
FUNCTION: "function";
IF: "if";
ARRAY:"array";
MOD: "mod";
NOT: "not";
OF: "of";
OR: "or";
PROCEDURE: "procedure";
PROGRAM: "program";
RECORD: "record";
THEN: "then";
TO: "to";
TYPE: "type";
VAR: "var";
WHILE: "while";
//========================================================[IDENTIFIER]
ID
options {testLiterals=true;}
: LETTER (LETTER|DIGIT|UNDERSCORE)*
;
//========================================================[WHITE SPACE]
WS
: (SPACE
| '\t'
| '\n'
| '\r')
{ $setType(Token.SKIP); }
;
//========================================================[INTEGER]
INT
: (DIGIT)+
;
//========================================================[SYMBOLS]
protected
SPACE
: ' '
;
PAREN_OPEN
: '('
;
PAREN_CLOSE
: ')'
;
OP_MULT
: '*'
;
OP_ADD_SUB
: '+'
| '-'
;
NOT_EQUAL
: "<>"
;
EQUAL
: '='
;
SEMICOLON
: ';'
;
COLON
: ':'
;
OP_GREATER
: '>'
;
OP_LESS
: '<'
;
GREATER_EQUAL
: ">=";
LESS_EQUAL
: "<="
;
PIPE
: '|'
;
BRAKET_S_OPEN
: '['
;
BRACKET_S_CLOSE
: ']'
;
BRACKET_C_OPEN
: '{'
;
BRACKET_C_CLOSE
: '}'
;
PERIOD_PERIOD: PERIOD PERIOD
;
PERIOD
: '.'
;
UNDERSCORE
: '_'
;
COMMA: ','
;
QUOTE: '"';
//========================================================[DIGITS]
protected
DIGIT
: '0'..'9'
;
//========================================================[LETTERS]
protected
LETTER
: ('a'..'z'|'A'..'Z')
;
More information about the antlr-interest
mailing list