flex lexer - How do you declare this macro in lex? -
i'm new lex , i'm confused on how declare following macro, keyword. want keyword consist of either "if", "then", "else", or "while."
i typed in lex:
keyword "if" | "then" | "else" | "while"
but compiler giving me "unrecognized rule error". when instead do
keyword "if"
it compiles ok.
is limitation of lex? know in jflex can did above , it'll work fine. or doing incorrectly?
thanks
i can't test right now, off top of head:
try putting values in parentheses (before first %%)
keyword ("if"|"then"|"else"|"while")
and use in rules (between %% , %%):
{keyword} {//action}
this how make class in lex, in rest of code can use {keyword}
, recognized regex you've assigned in definition section (before first %%). also, can use class part of other regexs:
{keyword}\{[^\}]\} {//action}
this recognizes whole block of code. (but doesn't check syntax inside block, leave :) )
Comments
Post a Comment