summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2013-03-23 09:30:11 -0400
committerAdrian Thurston <thurston@complang.org>2013-03-23 09:30:11 -0400
commit3227ec613e5350c67972bb4d36e8dc39cf7494e1 (patch)
tree6fa5427906ecd2d7c370581a0fc6ddaf00fd7fce
parent9ddc931cbacf4d270a7113d07092203bec8aaaae (diff)
downloadcolm-3227ec613e5350c67972bb4d36e8dc39cf7494e1.tar.gz
implemented multiplicative
-rw-r--r--colm/colm.lm14
-rw-r--r--colm/load.cc26
-rw-r--r--test/div.exp34
-rw-r--r--test/div.lm36
4 files changed, 64 insertions, 46 deletions
diff --git a/colm/colm.lm b/colm/colm.lm
index c782dd84..aff87c99 100644
--- a/colm/colm.lm
+++ b/colm/colm.lm
@@ -54,7 +54,7 @@ lex
token SQOPEN /'['/
token SQCLOSE /']'/
token BAR /'|'/
- token FSLASH /'/'/ ni
+ token FSLASH /'/'/
token COLON /':'/
token DOUBLE_COLON /'::'/
token DOT /'.'/
@@ -121,7 +121,7 @@ lex
token LEX_DOTDOT /'..'/
token LEX_SQOPEN_POS /'['/ ni
token LEX_SQOPEN_NEG /'[^'/ ni
- token LEX_FSLASH ni /'/'/
+ token LEX_FSLASH /'/'/
ignore /
( '\n' | '\t' | ' ' ) .
@@ -218,13 +218,13 @@ def region_def
[LEX RootItemList: root_item* END]
def rl_def
- [RL Id: id FSLASH Expr: lex_expr LEX_FSLASH]
+ [RL Id: id LEX_FSLASH Expr: lex_expr LEX_FSLASH]
def token_def
- [TOKEN Id: id FSLASH Expr: lex_expr LEX_FSLASH]
+ [TOKEN Id: id LEX_FSLASH Expr: lex_expr LEX_FSLASH]
def ignore_def
- [IGNORE FSLASH Expr: lex_expr LEX_FSLASH]
+ [IGNORE LEX_FSLASH Expr: lex_expr LEX_FSLASH]
def prod_el
[OptName: opt_prod_name Id: id OptRepeat: opt_repeat]
@@ -312,7 +312,9 @@ def code_additive
| [Multiplicitive: code_multiplicitive]
def code_multiplicitive
- [Unary: code_unary]
+ [Multiplicitive: code_multiplicitive Star: STAR Unary: code_unary]
+| [Multiplicitive: code_multiplicitive Fslash: FSLASH Unary: code_unary]
+| [Unary: code_unary]
def code_unary
[Bang: BANG Factor: code_factor]
diff --git a/colm/load.cc b/colm/load.cc
index b39973ce..cf6c9df3 100644
--- a/colm/load.cc
+++ b/colm/load.cc
@@ -151,7 +151,26 @@ struct LoadSource
LangExpr *walkCodeRelational( code_relational codeRelational );
LangExpr *walkCodeAdditive( code_additive codeAdditive );
- LangExpr *walkCodeMultiplicitive( code_multiplicitive codeMultiplicitive );
+
+ LangExpr *walkCodeMultiplicitive( code_multiplicitive mult )
+ {
+ LangExpr *expr;
+ if ( mult.Multiplicitive() != 0 ) {
+ LangExpr *left = walkCodeMultiplicitive( mult.Multiplicitive() );
+ LangExpr *right = walkCodeUnary( mult.Unary() );
+
+ if ( mult.Star() != 0 ) {
+ expr = LangExpr::cons( internal, left, '*', right );
+ }
+ else if ( mult.Fslash() != 0 ) {
+ expr = LangExpr::cons( internal, left, '/', right );
+ }
+ }
+ else {
+ expr = walkCodeUnary( mult.Unary() );
+ }
+ return expr;
+ }
ConsItemList *walkLitStringEl( lit_string_el litStringEl );
ConsItemList *walkLitStringElList( _repeat_lit_string_el litStringElList, CONS_NL Nl );
@@ -1161,11 +1180,6 @@ LangExpr *LoadSource::walkCodeAdditive( code_additive additive )
return expr;
}
-LangExpr *LoadSource::walkCodeMultiplicitive( code_multiplicitive codeMultiplicitive )
-{
- return walkCodeUnary( codeMultiplicitive.Unary() );
-}
-
LangExpr *LoadSource::walkCodeUnary( code_unary unary )
{
diff --git a/test/div.exp b/test/div.exp
deleted file mode 100644
index a6a72122..00000000
--- a/test/div.exp
+++ /dev/null
@@ -1,34 +0,0 @@
-0
-0
-0
-0
-1
-1
-1
-1
-2
-2
-2
-2
-3
-3
-3
-3
-4
-4
-4
-4
-5
-5
-5
-5
-6
-6
-6
-6
-7
-7
-7
-7
-8
-8
diff --git a/test/div.lm b/test/div.lm
index 2444ca6b..84dd8073 100644
--- a/test/div.lm
+++ b/test/div.lm
@@ -1,6 +1,42 @@
+##### LM #####
i: int = 0
while ( i < 34 ) {
print( (i / 4) '\n' )
i = i + 1
}
+##### EXP #####
+0
+0
+0
+0
+1
+1
+1
+1
+2
+2
+2
+2
+3
+3
+3
+3
+4
+4
+4
+4
+5
+5
+5
+5
+6
+6
+6
+6
+7
+7
+7
+7
+8
+8