Creating a foreach keyword using yacc or Bison and Flex

I developed an interpreted programming language. It is heavily based on C. The problem is that I want to add a directive foreachand don’t know how to do it.

I use Bison and Flex as a parser and lexer generator.

+3
source share
1 answer

In your grammar, you need an expression that looks something like this:

foreach := foreach ( name in name ) { statements }

When you analyze this, you should be able to translate it directly into the while loop in your AST with an optional expression that assigns the variable at the beginning.

, , , , (, ). , .

+4

Source: https://habr.com/ru/post/1717384/


All Articles