[RACC] Multiple entry points?


(Carlos) #1

Hi,

imagine I have a parser like this:

program: PROGRAM name ‘{’ statements ‘}’ { … }
;

statements: statement { … }
> statements statement { … }
;

statement: …

and I want to parse a single statement. How I can tell the parser to
start at ‘statement’ and return?

Thanks.


(Charles Comstock) #2

Carlos wrote:

Hi,

imagine I have a parser like this:

program: PROGRAM name ‘{’ statements ‘}’ { … }
;

statements: statement { … }
> statements statement { … }
;

statement: …

and I want to parse a single statement. How I can tell the parser to
start at ‘statement’ and return?

Thanks.

I think,

start statement

will do that, though if statement includes a reference to statements
obviously it will recurs.

Charlie


(Minero Aoki) #3

Hi,

In mail “[RACC] Multiple entry points?”

imagine I have a parser like this:

program: PROGRAM name ‘{’ statements ‘}’ { … }
;

statements: statement { … }
> statements statement { … }
;

statement: …

and I want to parse a single statement. How I can tell the parser to
start at ‘statement’ and return?

Use dummy token.

targets: PARSE_PROGRAM program /* PARSE_PROGRAM is a dummy token /
> PARSE_STATEMENT statement /
PARSE_STATEMENT is a dummy token */
;

program: …

statement: …

When you want to parse “program”, a lexer returns PARSE_PROGRAM at first.
When you want to parse “statement”, a lexer returns PARSE_STATEMENT at first.

Regards,
Minero Aoki

···

Carlos angus@quovadis.com.ar wrote:


(Carlos) #4

program: PROGRAM name ‘{’ statements ‘}’ { … }
;

statements: statement { … }
> statements statement { … }
;

statement: …

and I want to parse a single statement. How I can tell the parser to
start at ‘statement’ and return?

Use dummy token.

targets: PARSE_PROGRAM program /* PARSE_PROGRAM is a dummy token /
> PARSE_STATEMENT statement /
PARSE_STATEMENT is a dummy token */
;

program: …

statement: …

When you want to parse “program”, a lexer returns PARSE_PROGRAM at first.
When you want to parse “statement”, a lexer returns PARSE_STATEMENT at first.

A simple and clever solution! Thank you very much!