Re: [Google Groups] Parsing single expressions of a larger grammar

Skip to first unread message

Devin Cook

Sep 8, 2012, 3:09:01 PM9/8/12
It would probably be best to have two different grammars.

On Sat, Sep 1, 2012 at 4:23 PM, Aleksander Heintz <> wrote:
> I'm trying to write a grammar that can be used in 2 different ways, one is
> an interactive console, the other is running a "script" through my
> interpreter. For the later the grammar basically looks like this:
> <Program> ::= <Statement List>
> <Statement> ::= <For Stmt> | .... | <Expression Stmt>
> <Expression Stmt> ::= <Expression> ';'
> (note a lot has been omitted to make the code short. This means that for
> instance a valid script may look like this:
> 2+3;
> 3+5*2;
> However, simply writing 2+2 would be invalid, cause that would not be a
> statement. However, when in interactive console, this should be valid, as
> the interactive console should run both valid scripts and valid expressions.
> So I was wondering, do I need to different grammars with different
> start-symbols? Or can I achieve this in some other way?
> --
> You received this message because you are subscribed to the Google Groups
> "GOLD Parsing System" group.
> To view this discussion on the web visit
> To post to this group, send email to
> To unsubscribe from this group, send email to
> For more options, visit this group at

Christopher Wells

Sep 21, 2012, 2:10:10 PM9/21/12
You could try this:

1. Define your grammar as follows:

"Start Symbol" = <EitherOr>

<EitherOr> := '1' <Program> | '2' <Console>

<Console> := <Program> | <Expression>

2. At run-time this, prefix either '1' or '2' to the start of what you're parsing, before you invoke the parser.

It may also be also possible to do as follows:

1. Define the grammar as above

2. Add a customization to the run-time parser engine dll, to support changing/setting the engine's parser's "initial LALR state" on the fly
Reply all
Reply to author
0 new messages