commit bddaff23856a30010f977dc1d47707ee3899e89a
parent fcbb5efe862b8e8e98ae6edd7817d0aa5a6e992f
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Fri, 10 Jun 2022 06:38:00 -0400
cc: remove Factor AST node type
It was useless.
Diffstat:
2 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/fs/cc/ast.fs b/fs/cc/ast.fs
@@ -49,7 +49,7 @@ create bopsprectbl 1 c, 1 c, 0 c, 0 c, 2 c, 2 c, 2 c, 2 c,
6 value AST_ARGSPECS
7 value AST_EXPRESSION
8 value AST_UNARYOP \ data1=uopid
-9 value AST_FACTOR \ a constant or variable
+\ 9 = unused
10 value AST_BINARYOP \ data1=bopid
11 value AST_ASSIGN \ data1=name
12 value AST_DECLLIST
@@ -124,7 +124,6 @@ ASTIDCNT wordtbl astdatatbl ( node -- node )
: ArgSpecs ( -- ) -1 AST_ARGSPECS newnode ;
: Expression ( -- ) -1 AST_EXPRESSION newnode ;
: UnaryOp ( opid -- ) 1 AST_UNARYOP newnode , ;
-: Factor ( -- ) 1 AST_FACTOR newnode ;
: BinaryOp ( opid -- node ) 2 AST_BINARYOP newnode , ;
: Assign ( name -- ) 1 AST_ASSIGN newnode , ;
: DeclarationList ( -- ) -1 AST_DECLLIST newnode ;
@@ -167,8 +166,9 @@ ASTIDCNT wordtbl astdatatbl ( node -- node )
swap removenode to activenode ( bopid tgt )
swap BinaryOp ( tgt ) activenode addnode ;
-\ New parse words
+\ Parse words
+\ parse a constant, variable or function call
: parseFactor ( tok -- nexttok )
dup isIdent? if \ Variable or FunCall
_nextt ( prevtok newtok ) dup S" (" s= if \ FunCall
@@ -176,13 +176,12 @@ ASTIDCNT wordtbl astdatatbl ( node -- node )
else \ Variable
swap Variable ( nexttok ) then
else \ Constant
- expectConst Constant _nextt then
- seqclose ;
+ expectConst Constant _nextt then ;
: parseExpression ( tok -- )
dup S" ;" s= if drop AST_STATEMENTS closeuntil exit then
activeempty? if dup uopid if
- UnaryOp drop Factor _nextt parseFactor parseExpression exit then then
+ UnaryOp drop _nextt parseFactor parseExpression exit then then
dup bopid if ( tok binopid )
swap activeempty? if _err then \ can't start an expression with a binop
( bopid tok ) drop
@@ -190,8 +189,8 @@ ASTIDCNT wordtbl astdatatbl ( node -- node )
( bopid tgt ) 2dup data1 bopprec swap bopprec > if ( bopid tgt )
\ new binop has a higher precedence, steal right operand!
firstchild nextsibling then then
- binopswap Factor _nextt parseFactor parseExpression exit then
- Factor parseFactor parseExpression ;
+ binopswap _nextt parseFactor parseExpression exit then
+ parseFactor parseExpression ;
: parseDeclare ( tok -- )
'=' expectChar activenode data1 Assign Expression _nextt parseExpression ;
diff --git a/fs/tests/ccast.fs b/fs/tests/ccast.fs
@@ -10,7 +10,7 @@ curunit firstchild dup astid AST_FUNCTION #eq ( fnode )
dup data1 s s= #
firstchild nextsibling dup astid AST_STATEMENTS #eq ( snode )
firstchild dup astid AST_RETURN #eq ( rnode )
-firstchild ( expr ) firstchild ( factor )
+firstchild ( expr )
firstchild dup astid AST_CONSTANT #eq ( cnode )
data1 42 #eq
testend