I am trying to implement JavaScript parser in LPG, but I have some problems how to express things.
How to write the following things:
1) but not
Example:
SingleStringCharacter ::= SourceCharacter but not (single-quote ' or backslash \ or LineTerminator)
2) How to write grouping?
SingleStringCharacter ::= SourceCharacter but not (single-quote ' or backslash \ or LineTerminator)
3) How to write optionality?
DoubleStringCharacters ::= DoubleStringCharacter DoubleStringCharactersopt
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
1, As far as I know, the parser generator does not support direct negation. Instead of that you have to manually invert the elements, e.g.
SingleStringCharacter ::= Alphabet | Numeric | '?' | '!' | etc. etc.etc.
2, Sorry, but I don't see whats different from the first question.
3, You have to define a new nonterminal with options:
DoubleStringCharacters ::= DoubleStringCharacter DoubleStringCharactersOpt
DoubleStringCharactersOpt ::= DoubleStringCharacter | %empty
Hello,
I am trying to implement JavaScript parser in LPG, but I have some problems how to express things.
How to write the following things:
1) but not
Example:
SingleStringCharacter ::= SourceCharacter but not (single-quote ' or backslash \ or LineTerminator)
2) How to write grouping?
SingleStringCharacter ::= SourceCharacter but not (single-quote ' or backslash \ or LineTerminator)
3) How to write optionality?
DoubleStringCharacters ::= DoubleStringCharacter DoubleStringCharactersopt
Hi,
1, As far as I know, the parser generator does not support direct negation. Instead of that you have to manually invert the elements, e.g.
SingleStringCharacter ::= Alphabet | Numeric | '?' | '!' | etc. etc.etc.
2, Sorry, but I don't see whats different from the first question.
3, You have to define a new nonterminal with options:
DoubleStringCharacters ::= DoubleStringCharacter DoubleStringCharactersOpt
DoubleStringCharactersOpt ::= DoubleStringCharacter | %empty
Or a similar solution
DoubleStringCharacters ::= DoubleStringCharacter | DoubleStringCharacter DoubleStringCharacters
I hope I have helped,
Zoltán Ujhelyi
Thanks, it helped.
And btw: how could I write the following?
EscapeSequence ::=
CharacterEscapeSequence
| 0
| HexEscapeSequence
| UnicodeEscapeSequence
Thanks a lot
Jan