-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
question #1
Comments
Nope: I didn't know about it. Looks like a willing-to-modify-yacc approach to http://people.via.ecp.fr/~stilgar/doc/compilo/parser/Generating%20LR%20Syntax%20Error%20Messages.pdf (as opposed to the approach taken by rsc (referencing the same paper) at http://research.swtch.com/yyerror. Thanks for the pointer. I'll probably stick with the go tool yacc for this, since it's just a classroom compiler, and everyone is guaranteed to have it :-) |
can you generate good error messages if the syntax of the cool source is not correct? |
For a classroom compiler, yes :-) In fact, the test data they give you to check against has fairly typical Zellyn On Tue Nov 18 2014 at 12:42:32 AM geraldstanje [email protected]
|
any updates on error handling? |
I got a lot of mileage out of reading https://code.google.com/p/rsc/source/browse/cc/ - it does #include at the lexer level. I'm not sure about #ifdef. |
where do you store variable declarations within functions/methods? |
Sorry for the unclear question. I was saying you need to implement a stack for local variable declarations within functions... |
Yep. But I'm just now implementing the compiler, so I have't got there yet. For typechecking, I'm using this: https://github.com/zellyn/gocool/blob/master/symbols/symbols.go |
can you give me some feedback to my toy compiler? https://github.com/geraldstanje/toycompiler i would also like to add function, if statements and variables ... im not sure how to implement scoping...any comments? |
Which areas in particular would you like feedback on? I haven't got all the way through the implementation of scoping, but what's done is mostly in https://github.com/zellyn/gocool/blob/master/symbols/symbols.go Basically, each time you encounter a variable in a new scope, you push it on the stack. Some implementations push a whole new scope on a stack of scopes. But Cool is so simple that I don't think I'm going to need those. You'll notice that queries of symbol tables run from the end backwards, so you always search the most nested scopes first. I've been using the coursera compilers class as my reference: I think I've watched all the relevant videos at least twice now. |
about the design of the toy compiler...i still need to add proper testing and split into packages... so i would best add the scoping into https://github.com/geraldstanje/toycompiler/blob/master/codegen.go and add FuncCallNode, IfNode, VarDeclNode into func (c *AsmCodeGenerator) compNode(node Node)? i guess i also need the prev scope in case i do: int main() { |
So, at least for Cool, a function has its own scope (well, plus the Object properties). So foo wouldn't care about the a in main(). That would be dynamic scope, like in elisp. :-) |
ok, i don't refer to cool :) so for the variable a in foo I would need to lookup the varDecl in the prev scope? |
Hi,
did you also think about using: https://github.com/cznic/goyacc ?
Thanks,
-Gerald
The text was updated successfully, but these errors were encountered: