LEX–YACC LabCSL411 Compiler Lab · tokens → grammar → a working program
0 · The question
1 · Tokens: what LEX reads and what it passes on
One row per kind of lexeme, in order: on a tie LEX picks the earlier row, otherwise the longest match wins.
In a LEX+YACC program each useful row ends with return NAME; — that NAME is the token YACC sees.
Definitions (optional, e.g. digit [0-9], used as {digit})
#Pattern (regular expression)Action (C code)
Quick add:
2 · Grammar: the YACC productions
Write productions the YACC way: S : A S B on one line, | alternative on the next, ; to end. An empty alternative is just | with nothing after it. Characters go in single quotes: '+'. Put actions at the end: { $$=$1+$3; }.
Tokens from step 1:
main() body (default: yyparse();)
3 · Try it
The board runs your rules and grammar right here in the browser, the way LEX and YACC would. One input per box; the newline at the end counts.
4 · Your program, in the lab-manual format
Your rows and productions, wrapped in the same skeleton as the lab manual. Copy them to the lab machine (or an online LEX/YACC runner) and build with the commands below.
Build & run
✍ Write:
AI tutor: your own free NVIDIA key
Get a free key at build.nvidia.com (it starts with nvapi-). It stays in this browser only, and each question is relayed once to NVIDIA and never stored. Everything except Unstuck and Ask works without a key.