Commit graph

44 commits

Author SHA1 Message Date
Randy Heit
c0dd39ffd4 Use %token_class to define intconst 2016-03-20 15:57:01 -05:00
Randy Heit
260cf6848f Use LHS and RHS label matching in the grammars where possible 2016-03-20 15:57:01 -05:00
Randy Heit
1c592c9601 Lemon update 2009-11-03 19:18:32 on branch trunk
- Enhancements to lemon to generate more compact action tables and to avoid making array bounds tests that can never fail on action table calculations. (user: drh)
- Update zcc-parse.lemon: YY_SZ_ACTTAB is now YY_ACTTAB_COUNT
2016-03-20 13:06:43 -05:00
Randy Heit
aaae9f2e05 Store known but uncompiled nodes in the symbol table
- Don't bother keeping track of uncompiled nodes in a special table. Use
  the regular symbol table instead. This should in the future make
  compiling nodes referenced deeper than (and before) their definitions
  fairly straightforward.
- Also, break up the compiler's Message() function into Warn() and Error()
  and get rid of zcc_errors.h. I can't really see having a set of error
  numbers being useful.
2016-03-18 19:34:32 -05:00
Randy Heit
4a295dfa3d Accept constant definitions in structs.
- We already need to handle them for enums, so there's really nothing to
  be gained by not accepting constant definitions directly.
2016-03-12 19:11:34 -06:00
Randy Heit
2e588c2099 Add missing SEMICOLON to declarator_no_fun 2016-03-10 10:33:19 -06:00
Randy Heit
964ff46063 Add new state options to parser and actually enable them
- Added new state options that DECORATE got to the lemon parser.
- Enable token generation for state options. They were previously not
  generated, so the grammar treated them as function calls instead.
2016-03-03 18:33:07 -06:00
Randy Heit
55142078d8 Normalize line endings 2016-03-01 09:47:10 -06:00
Randy Heit
1482070207 Comment out SCOPE parsing for now 2015-06-13 18:19:38 -05:00
Randy Heit
03c4244fd8 Accept only one identifier for class names. 2013-10-29 22:05:09 -05:00
Randy Heit
2b96db5fac Do not share constant 1 for enum autoincrements.
- AST nodes cannot be shared, because type conversion changes them in
  place, and what's appropriate for one use is by no means appropriate for
  all uses.
2013-10-25 22:30:25 -05:00
Randy Heit
d0968af9a6 Separate the AST from the parser state. 2013-10-25 22:30:24 -05:00
Randy Heit
4bd5bf310b Do not use GT, GTEQ, or NEQ operators in the AST.
- Since the VM doesn't directly support the GT, GTEQ, and NEQ comparisons,
  don't use them in the trees either. Instead, wrap them as LTEQ, LT, and
  EQEQ inside a BoolNot operator.
2013-10-02 23:28:06 -05:00
Randy Heit
a0dbcb5d5b Add TRUE and FALSE terminals to the zcc grammar
- I can't believe I completely forgot to let the parser handle true and
  false literals.
- Consolidate all the %include blocks in zcc-parse.lemon into a single
  one, because Lemon all of a sudden decided it didn't like me having more
  than one in the grammar file.
- Added a PBool type to represent boolean values with.
2013-09-28 21:16:44 -05:00
Randy Heit
743b05189e Give the parser knowledge of constants for unary - and +
- Since the tokenizer never gives the parser negative numbers but always a
  unary minus followed by a positive number, it seems reasonable to make
  the parser smart enough to turn these into negative constants without
  generating extra tree nodes.
- And since we're doing it for unary -, we might as well do it for unary +
  as well and avoid extra nodes when we know we don't need them.
2013-09-12 22:22:43 -05:00
Randy Heit
2a1414ad66 Use labels in autogenerated enum value expressions
- For an enum like this:
    enum { value1 = SOME_NUM*2, value2 };
  Generate an increment expression for value2 of the form
    (add (id value1) 1)
  and not
    (add (* SOME_NUM 2) 1)
2013-09-12 22:06:57 -05:00
Randy Heit
af8e0f2ba6 Represent enumerations as constant definitions
- Instead of representating enumeration values with a special node type,
  use the same ZCC_ConstantDef nodes that const_def produces. These are
  created at the same scope as the ZCC_Enum, rather than being contained
  entirely within it. To mark the end of enums for a single instance of
  ZCC_Enum, a ZCC_EnumTerminator node is now appended to the chain of
  ZCC_ConstantDefs.
2013-09-12 22:00:49 -05:00
Randy Heit
33e835b58d Accept name constants in the grammar 2013-09-10 21:56:13 -05:00
Randy Heit
1b4851224e Let the grammar accept unsigned integer constants 2013-09-10 21:44:32 -05:00
Randy Heit
6545c48e07 Accept constant definitions at global scope 2013-09-10 21:25:50 -05:00
Randy Heit
61666e1515 Consolidate constant expression nodes into a single type
- Instead of having ZCC_ExprString, ZCC_ExprInt, and ZCC_ExprFloat,
  just use a single ZCC_ExprConstant. It should simplify type
  promotion and constant folding in the future.
2013-09-10 21:10:48 -05:00
Randy Heit
f9f8d1e79b Add a type field for ZCC expressions.
- Constants can fill out the type field right away. Other expressions will need
  to wait until a later pass, after names have been resolved, so they get
  initialized to NULL.
2013-09-10 20:50:21 -05:00
Randy Heit
2823ea5de3 Annote AST nodes with source information 2013-08-28 22:59:03 -05:00
Randy Heit
064710422b Accept empty struct and enum definitions (useless as they may be) 2013-08-24 20:32:59 -05:00
Randy Heit
80daf736ec Accept enums and structs defined at global scope 2013-08-24 20:28:26 -05:00
Randy Heit
11b588de4a Add names for fallback tokens.
- Fixed: When falling back to the IDENTIFIER token, the identifier it
  would get was undefined, because it never got initialized.
2013-08-02 21:54:50 -05:00
Randy Heit
7d304a4cb6 Partially revert commit 46c0127
- Being able to omit optional function arguments is not such a nonsensical
  thing after all. However, the previous grammar was still inadequate for
  representing this in a useful way.
2013-07-24 20:59:29 -05:00
Randy Heit
a136ca65ea Allow functions without parameters
- Fixed: Trying to define a function without any parameters would silently
  discard the function, because the declarator tested FuncParams instead
  of FuncName to decide if it was a function.
2013-07-23 20:43:15 -05:00
Randy Heit
67caf3303b Add the array size to ZCC_VarName 2013-07-23 19:59:47 -05:00
Randy Heit
0d25ed8289 state_call needs parenthesis around func_expr_list
- Fixed: state_call needs to enclose func_expr_list in LPAREN/RPAREN
  itself, because func_expr_list doesn't include them. This means it also
  needs a separate production to accept calls without a parameter list.
2013-07-23 19:34:21 -05:00
Randy Heit
46c0127ebb Don't accept function params starting with a comma
- Fixed: func_expr_list would accept nonsense like this:
    Myfunction(, 1, 2);
2013-07-23 19:28:58 -05:00
Randy Heit
733e5fa2e1 Recognize C-style array declarations
- The variable_name production now accepts an optional array size
  argument. (Not yet passed to the AST.)
- The notation for using dotted ID lists as types has been changed from
  [id1.id2] to .id1.id2, beacuse the former conflicts with the notation
  for arrays.
2013-07-19 23:25:01 -05:00
Randy Heit
a7bbe299e3 Assignment for expr ::= unary_expr was backwards 2013-07-13 23:25:53 -05:00
Randy Heit
ec32248f31 Set value of assign_op explicitly. 2013-07-13 22:34:33 -05:00
Randy Heit
62fb43d67a Properly pass statements around in the parser. 2013-07-13 22:26:29 -05:00
Randy Heit
6088acd4c0 Add function body to ZCC_FuncDeclarator 2013-07-10 23:26:56 -05:00
Randy Heit
2d139f3846 - DoParse() now writes out the parsed AST for the input file to <file>.ast.
Maybe TODO: Find a simple LISP pretty printer that isn't written in LISP so that the output
  isn't all on one big long line.
- zcc-parse.lemon now returns the complete AST through the parse state.
- Fixed crash in PrintEnumNode().

SVN r3773 (scripting)
2012-07-20 02:54:51 +00:00
Randy Heit
4b8900816b - Make the ZCC parser compilable again. Does every rule in the grammar that needs to appear in
the AST do so now? That would sure be nice.

SVN r2715 (scripting)
2010-09-08 04:32:31 +00:00
Randy Heit
12c6ddfbfb - So, progress...
SVN r2707 (scripting)
2010-09-07 04:11:32 +00:00
Randy Heit
081ebbb64b - I have decided to opt for simplicity over C-like-ness and group array sizes with the rest
of the type declaration rather than split it up after the variable name.
- More AST work. At this rate, maybe I'll finally be building a complete AST by the end of the
  month!

SVN r2499 (scripting)
2010-08-10 04:25:52 +00:00
Randy Heit
9d931ed10c - Make AST nodes for states.
SVN r2425 (scripting)
2010-07-11 18:53:41 +00:00
Randy Heit
85d869315b - More AST'ing about.
SVN r2359 (scripting)
2010-06-06 21:04:55 +00:00
Randy Heit
c043627cc1 - Some abstract syntax tree creation stuff. (Plus some tentative type creation stuff that made
me realize I would be better off creating a type-agnostic AST for the entire input instead
  of trying to tentatively create types before they're seen.)

SVN r2354 (scripting)
2010-06-06 04:15:28 +00:00
Randy Heit
7aa402b2a5 - Add a preliminary grammar and a test driver for it.
SVN r2233 (scripting)
2010-03-19 04:04:13 +00:00