Related articles |
---|
parse last line aw0g+@andrew.cmu.edu (Aaron Wohl) (1995-02-17) |
Re: parse last line umrigar@cs.binghamton.edu (Zerksis D. Umrigar) (1995-02-21) |
Re: parse last line jpowers@ti.com (1995-02-21) |
Newsgroups: | comp.compilers |
From: | Aaron Wohl <aw0g+@andrew.cmu.edu> |
Keywords: | lex, parse, question |
Organization: | Systems Group 97, Carnegie Mellon, Pittsburgh, PA |
Date: | Fri, 17 Feb 1995 13:10:26 GMT |
How do folks handle parsing the last line of input?
I am using lex/yacc for a new compiler for an obscure basic dialect that
up until now has only been interpreted. It is fairly common for the
basic programs to not have and end of line character on the last line.
My grammar looks like:
program:
stmt
| program stmt
;
stmt:
EOL
| NEXT EOL
| RETURN EOL
| ID ':' stmt
| ID '=' exp EOL
...
All the stuff I tried to allow the last EOL to be optional ended up with
shift/reduce conflicts on ID. I tried replacing the lex character
input to return an extra eol before eof. But different versions of
yacc/bison/etc override the character input differently. What I ended
up doing was putting a function between yacc and lex. When lex returns
EOF it returns EOL once then EOF.
Is there a good way to allow EOL to be a statement terminator but
optional at EOF that is portable to different yacc/lex dialects?
Aaron Wohl / ham callsign N3LIW / 412-731-3691 / 412-268-5032
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.