Updated with Shultz's new changes
This commit is contained in:
Executable → Regular
+49
-12
@@ -2,18 +2,16 @@ Note: this is the draft grammar, with notes and some thoughts,
|
||||
for the Project 2 version of Corgi
|
||||
------------------
|
||||
|
||||
<program> -> <funcCall> <funcDefs>
|
||||
<program> -> <funcCall> | <funcCall> <funcDefs>
|
||||
|
||||
<funcDefs> -> <funcDef> | <funcDef> <funcDefs>
|
||||
|
||||
<funcDef> -> def <funcName> ( ) end |
|
||||
def <funcName> ( <params> ) end |
|
||||
def <funcName> ( ) <statements> end
|
||||
def <funcName> ( <params> ) <statements> end
|
||||
<funcDef> -> def <var> ( ) end |
|
||||
def <var> ( ) <statements> end
|
||||
def <var> ( <params> ) end |
|
||||
def <var> ( <params> ) <statements> end
|
||||
|
||||
<funcName> -> <var>
|
||||
|
||||
<params> -> <var> | <var> <params>
|
||||
<params> -> <var> | <var> , <params>
|
||||
|
||||
<statements> -> <statement> |
|
||||
<statement> <statements>
|
||||
@@ -21,7 +19,7 @@ Note: this is the draft grammar, with notes and some thoughts,
|
||||
<funcCall> -> <var> ( ) |
|
||||
<var> ( <args> )
|
||||
|
||||
<args> -> <expr> | <expr> <args>
|
||||
<args> -> <expr> | <expr> , <args>
|
||||
|
||||
<statement> -> <string> |
|
||||
<var> = <expr> |
|
||||
@@ -35,7 +33,7 @@ Note: this is the draft grammar, with notes and some thoughts,
|
||||
<expr> -> <term> | <term> + <expr> | <term> - <expr>
|
||||
<term> -> <factor> | <factor> * <term> | <factor> / <term>
|
||||
|
||||
<factor> -> <number> | <var> |
|
||||
<factor> -> <num> | <var> |
|
||||
( <expr> ) |
|
||||
- <factor> |
|
||||
<funcCall>
|
||||
@@ -59,8 +57,47 @@ Notes:
|
||||
change the Lexer to remove /* ..... */ type of comments---no tokens
|
||||
produced
|
||||
|
||||
change Lexer to allow \n inside a string---put \\ in the Java string
|
||||
NO! change Lexer to allow \n inside a string---put \\ in the Java string?
|
||||
This is mildly irritating, worth adding a bif: nl()
|
||||
|
||||
While doing Project 2 I noticed that it's easier if we require all
|
||||
functions to return (saves handling difference between hitting "end"
|
||||
at the end of function that didn't do a return, and hitting "end"
|
||||
elsewhere).
|
||||
So, if you want to, it's okay to assume that all functions return on all
|
||||
execution paths (just do like [return 0] if the function doesn't really
|
||||
feel like returning a number.
|
||||
|
||||
Need to agree on names for all the many BIF's---see upcoming document
|
||||
Also, it's okay to require the initial funcCall to not be to a built-in
|
||||
function (in my implementation, seems to be a problem (could probably be
|
||||
easily fixed, but is a silly feature, anyway).
|
||||
|
||||
Here are the tentative official built-in functions:
|
||||
|
||||
lt( , ) returns 1 if first arg is less than the second
|
||||
0 otherwise
|
||||
le( , ) " less than or equal to "
|
||||
eq( , ) " equal to
|
||||
ne( , ) " not equal
|
||||
|
||||
or( , ) returns 1 if either arg is non-zero, 0 otherwise
|
||||
and( , ) returns 1 if both args are non-zero, 0 otherwise
|
||||
|
||||
not( ) returns 1 if arg is zero, 0 otherwise
|
||||
|
||||
all the original Corgi bifs (input(), sqrt, cos, sin, atan,
|
||||
pow( <expr>, <expr> )
|
||||
|
||||
some new ones:
|
||||
|
||||
print( <expr> ) just like in original Corgi, except say that if
|
||||
the decimal part is 0, then don't display the .0
|
||||
(this is the only bif that is called as a statement)
|
||||
NOTE: print should ideally NOT display the decimal part if
|
||||
it is 0 --- i.e., want 37, not 37.0
|
||||
nl() prints a newline
|
||||
(NOTE: unlike all other functions, funcCall to print and nl
|
||||
are statements, don't return a value)
|
||||
|
||||
round( <expr> ) returns the value rounded to nearest integer
|
||||
trunc( <expr> ) returns the value with the decimal part set to 0
|
||||
|
||||
Reference in New Issue
Block a user