|Ignore break line sometimes email@example.com (Geovani de Souza) (2012-02-11)|
|RE: Ignore break line sometimes firstname.lastname@example.org (Karsten Nyblad) (2012-02-12)|
|Re: Ignore break line sometimes email@example.com (Kaz Kylheku) (2012-02-13)|
|From:||"Karsten Nyblad" <firstname.lastname@example.org>|
|Date:||Sun, 12 Feb 2012 09:21:48 +0100|
|Posted-Date:||12 Feb 2012 16:14:24 EST|
> I'm trying write an parser to my compiler, and I'm interessed to
ignore the break line (\n) sometimes. E.g:
> if true then [\n]
> foo(); [\n]
> end; [\n]
One option is to write a recursive descendent parser, and have two ways
of calling the lexer: One that return line ends and one that does not.
An other option is to base your parsing on a parser generator like
bison, and modify the code that drives the automaton. That code is
modified such that when the lexer returns a line feed token, you copy
the stack of states, and on the copy you simulate the actions that the
parser would have taken. When the simulation stacks the line feed, you
throw away the copy and resume parsing on the real stack with the line
feed in the window. When the simulation encounters an error, you throw
away the simulation AND the line feed and call the lexer again.
If you chose the second option, it is important that you chose the right
parser generator, because some parser generators already generate code
that can help you. Many LR parser generators, e.g., bison, include
facilities for generalised LR parsing, and many LL parser generators
include facilities for backtracking. That might help you.
Return to the
Search the comp.compilers archives again.