Initial Commit
This commit is contained in:
Executable
+66
@@ -0,0 +1,66 @@
|
||||
Note: this is the draft grammar, with notes and some thoughts,
|
||||
for the Project 2 version of Corgi
|
||||
------------------
|
||||
|
||||
<program> -> <funcCall> <funcDefs>
|
||||
|
||||
<funcDefs> -> <funcDef> | <funcDef> <funcDefs>
|
||||
|
||||
<funcDef> -> def <funcName> ( ) end |
|
||||
def <funcName> ( <params> ) end |
|
||||
def <funcName> ( ) <statements> end
|
||||
def <funcName> ( <params> ) <statements> end
|
||||
|
||||
<funcName> -> <var>
|
||||
|
||||
<params> -> <var> | <var> <params>
|
||||
|
||||
<statements> -> <statement> |
|
||||
<statement> <statements>
|
||||
|
||||
<funcCall> -> <var> ( ) |
|
||||
<var> ( <args> )
|
||||
|
||||
<args> -> <expr> | <expr> <args>
|
||||
|
||||
<statement> -> <string> |
|
||||
<var> = <expr> |
|
||||
<funcCall> |
|
||||
if <expr> else end |
|
||||
if <expr> else <statements> end |
|
||||
if <expr> <statements> else end |
|
||||
if <expr> <statements> else <statements> end |
|
||||
return <expr>
|
||||
|
||||
<expr> -> <term> | <term> + <expr> | <term> - <expr>
|
||||
<term> -> <factor> | <factor> * <term> | <factor> / <term>
|
||||
|
||||
<factor> -> <number> | <var> |
|
||||
( <expr> ) |
|
||||
- <factor> |
|
||||
<funcCall>
|
||||
|
||||
|
||||
Notes:
|
||||
|
||||
slightly bizarre but cool: in Corgi you can just type a string anywhere
|
||||
as a statement and it gets sent to the console (still have to use
|
||||
print( <expr> ) to send a number)
|
||||
|
||||
no boolean type---use "non-zero is true, 0 is false"
|
||||
|
||||
there's only the if-else---always have to use it
|
||||
|
||||
no loop statements---use recursion!
|
||||
|
||||
the built-in functions fit the grammar just like user-defined functions---
|
||||
will execute differently
|
||||
|
||||
change the Lexer to remove /* ..... */ type of comments---no tokens
|
||||
produced
|
||||
|
||||
change Lexer to allow \n inside a string---put \\ in the Java string
|
||||
|
||||
|
||||
Need to agree on names for all the many BIF's---see upcoming document
|
||||
|
||||
Reference in New Issue
Block a user