Page 1 of 1
How to create Rules for 2 Versions
Posted: 25.10.2018 21:09
by Shando
Hi all,
How would I create Rules for the following variations of the same statement:
Code: Select all
if first
> "First Parameter: ", first
end
if second: > "Second Parameter: ", second
Thanks in advance
Shando
Posted: 26.10.2018 06:42
by Alexey
Seems, rule-1 will be "if <Id> > ......." with ending rule "end".
and rule-2 will be "if <Id> : > ......" without ending rule.
It's so if "first/second" are Id. If they are expressions, then:
instead of <Id> add "skip tokens" for several token types: <Id> <Symbol> <String> etc.
You need to skip <Symbol> so symbols > and : must be of different name, e.g. <SymbolGreater>, <SymbolColon>
Posted: 26.10.2018 12:19
by Shando
Hi Alexey,
Thanks for the reply.
I've tried what you suggested, but must be doing something wrong as I can't get it to work...
Basically, the grammar is as follows:
if <expression> <eol> <statement_list>* <elif_or_else>* <end> <eol>
and
if <expression> <colon> <statement> <eol>
* = can be multiple as per standard if .. else statements
Any further help would be greatly appreciated.
Regards
Shando
Posted: 26.10.2018 13:32
by Alexey
I will help with ready example of lexer- e.g. small lexer with 2 these rules.