Master the fundamental concepts of syntax analysis through this focused micro-challenge.
Yacc and Bison generate LR parsers from grammars. An LR(1) table maps (state, lookahead) to shift, reduce, accept, or error actions. GCC's old Java parser and many language specs use LR because it handles left recursion and large grammars mechanically.
For a small grammar, compute item sets: dotted productions like E -> E . + T. Closure adds items implied by nonterminals after the dot. GOTO maps states on nonterminals; ACTION maps states on terminals. Conflicts (shift/reduce) reveal grammar ambiguity.
cLoading…
Production compilers embed this step inside a longer pipeline. GCC flows through cpp, cc1, assembly, and ld; Clang uses the driver, Sema, LLVM IR passes, and a target backend. LLVM bitcode, JVM bytecode, and WASM are other familiar IRs at the same layer. The exercise isolates one pass so you can test it alone before chaining it to the next stage.
You will construct an LR(1) parser table by hand for a small expression grammar. This exercise asks you to compute item sets, fill ACTION and GOTO tables, and trace parse steps on sample input.
Implement an LR(1) parser table by hand for a simple expression grammar.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github