Menu

Grammar questions

Help
Anonymous
2011-03-31
2013-04-25
  • Anonymous

    Anonymous - 2011-03-31

    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

     
  • Zoltán Ujhelyi

    Zoltán Ujhelyi - 2011-03-31

    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

     
  • Anonymous

    Anonymous - 2011-04-01

    Thanks, it helped.

    And btw: how could I write the following?
    EscapeSequence ::=
                       CharacterEscapeSequence
                        | 
                        | HexEscapeSequence
                        | UnicodeEscapeSequence

    Thanks a lot
    Jan

     

Log in to post a comment.