Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>(disclaimer) I don't have much experience with compiler classes (as in school courses on compilers) but here's what I understand:</p> <p>1) You need to use the tools mentioned to create a parser which, when given input will tell the user if the input is a correct program as to the grammar defined in cminus.y. I've never used yacc/bison so I don't know how it is done, but this is what seems to be done:</p> <ul> <li>(input) file-of-some-sort which represents output to be parsed</li> <li>(output) reply-of-some-sort which tells if the (input) is correct with respect to the provided grammar.</li> </ul> <p>2) It also seems that the output needs to check for variable consistency (ie, you can't use a variable you haven't declared same as any programming language), which is done via a symbol table. In short, every time something is declared you add it to the symbol table. When you encounter an identifier, if it is not one of the language identifiers (like <code>if</code> or <code>while</code> or <code>for</code>), you'll look it up in the symbol table to determine if it has been declared. If it is there, go on. If it's not - print some-sort-of-error</p> <p>Note: point(2) there is a simplified take on a symbol table; in reality there's more to them than I just wrote but that should get you started.</p> <p>I'd start with yacc examples - see what yacc can do and how it does it. I guess there must be some big example-complete-with-symbol-table out there which you can read to understand further.</p> <p>Example:</p> <p>Let's take input A:</p> <pre><code>int main() { int a; a = 5; return 0; } </code></pre> <p>And input B:</p> <pre><code> int main() { int a; b = 5; return 0; } </code></pre> <p>and assume we're using C syntax for parsing. Your parser should deem Input A all right, but should yell "b is undeclared" for Input B.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload