S
S
Sergey Tikhonov2015-08-17 21:38:41
Programming languages
Sergey Tikhonov, 2015-08-17 21:38:41

How to describe WHILE in yacc?

I am writing a compiler (Homework) in lex & yacc. The assignment states that I should have an iterator like this:
repeat
|expression|
until |condition|
In yacc I describe the following rules:
repeat_statement: REPEAT line UNTIL condition { I can't understand - how can I describe the cycle here? }
;
REPEAT and UNTIL are tokens.
line is a set of rules:
line: /* empty */
| comment line
| assigned line
| print line
| repeat_statement line
;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2015-08-18
@Keyon

What is your question?
If in "I can't figure out how to describe a cycle here", then in this place you need to create an AST node (or what is your internal representation of the program structure) that describes the cycle, referring to the body of the cycle (line, $2) and the termination condition (condition , $4).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question