[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

Similar Threads

Syntax error 2
SYNTAX ERROR 0
Is there a way to get a single mode using all the points within a 2D array? 2
Racc error recovery 4
Can't install racc 2
Racc fails on install 7
Racc 2
Fun with RACC examples 3

Members online

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top