[RACC] Multiple entry points?

C

Carlos

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.
 
C

Charles Comstock

Carlos said:
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
 
M

Minero Aoki

Hi,

In mail "[RACC] Multiple entry points?"
Carlos said:
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
 
C

Carlos

program: PROGRAM name '{' statements '}' { ... }
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top