Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question