[antlr-interest] rules for complicated strings
jbb at acm.org
jbb at acm.org
Mon Jan 27 18:24:36 PST 2003
>How do I store a value read in from file, and reference the value later in
>the program?
I'd use a Hashtable, v is the key and d is its datum. And also study
the general Compiler literature regarding Symbol Tables and their use.
>Next, is there a good way I can specify a rule to represent complicated
>strings like this:
>
>P(age) --> {.g(1)[-(90)g(1).][g(MAX_P_LEN*func(2,age/DURATION)).][+(90)g(1).]}
>
>where parenthesis and brackets occur randomly and on both sides of the
>equation?
How 'bout this:
--------------------------------------------------
class hushlee83Parser extends Parser;
entry : expr EOF ;
expr :
( OTHER
| LPAREN expr RPAREN
| LBRACE expr RBRACE
| LBRACKET expr RBRACKET )+
;
class hushlee83Lexer extends Lexer;
options{charVocabulary='\3'..'\377';}
LPAREN : '(';
RPAREN : ')';
LBRACE : '{';
RBRACE : '}';
LBRACKET : '[';
RBRACKET : ']';
OTHER : (~('('|')'|'['|']'|'{'|'}'))+;
--------------------------------------------------
assuming that the parens, braces, and brackets must appear in pairs.
Hope this helps...
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list