Commit graph

417 commits

Author SHA1 Message Date
Charles Baker
a5db5713da Remove unused GrammarSymbolLess 2023-05-28 20:45:44 +12:00
Charles Baker
faaafdcef6 Remove GrammarProduction pointer from GrammarItem 2023-05-28 20:45:44 +12:00
Charles Baker
9d90804ae2 Use a vector of active GrammarStates to track new states
The previous algorithm would loop through all states but only process
those that didn't have their processed flag set.  Much faster to only
iterate through those states that haven't been processed.
2023-05-26 22:07:34 +12:00
Charles Baker
ebe173cb12 Parse arrays in the JSON example 2023-05-26 21:53:01 +12:00
Charles Baker
c5a7c1728d Generate errors for missing lexical action handlers 2023-05-21 21:00:37 +12:00
Charles Baker
77602f9052 Test that parsers with missing lexical action handlers generate errors 2023-05-21 20:15:29 +12:00
Charles Baker
d8948dd936 Report missing action handlers from Parser::valid() 2023-05-21 20:15:12 +12:00
Charles Baker
184a8b34c0 Report missing lexical action handlers from Lexer::valid() 2023-05-21 20:04:14 +12:00
Charles Baker
e56556f390 Move Parser::fire_{error,print}() and Parser::is_debug_enabled() to const member section 2023-05-21 20:03:36 +12:00
Charles Baker
b7b7c4d61e Move Lexer::set_action_handler() to non-const member section 2023-05-21 19:53:56 +12:00
Charles Baker
5ce357e651 Treat empty character classes in a regular expression as an error 2023-05-20 22:15:47 +12:00
Charles Baker
aaea898aab Allow most metacharacters in character classes, e.g. allow "[+-]"
Allows most metacharacters, e.g. "*+()[", to appear unescaped within a
character class.  This, along with hyphens at the end, allows "[+-]" to
match a plus or a minus.
2023-05-20 22:15:47 +12:00
Charles Baker
2235e9fe6b Stop Lexer reading past end of input when skipping whitespace 2023-05-20 21:01:39 +12:00
Charles Baker
eb23625604 Simplify lexer state generation in RegexGenerator 2023-05-19 20:15:01 +12:00
Charles Baker
0e8a1e96b6 Declare write_graphviz_dot() in dot.hpp, include from lalrc.cpp 2023-05-19 20:15:01 +12:00
Charles Baker
cee6d1372a Rename RegexState::get_index() to RegexState::index() 2023-05-19 20:15:01 +12:00
Charles Baker
76d51795f3 Remove trailing newline from C++ output 2023-05-19 20:15:01 +12:00
Charles Baker
02210884a3 Implement RegexItem::operator<() with std::lexicographical_compare()
Using set<>::operator<() doesn't generate a stable comparison wrt. the
nodes in the item.  This is either set<>::operator<() not behaving as
a lexicographical compare like I expect or not taking into account the
comparison object the set is initialized with.

Fixes non-deterministic lexer generation.
2023-05-19 20:15:01 +12:00
Charles Baker
6750cb1769 Store ParserSymbol in whitespace lexer tokens matched symbol
Previously this cast a GrammarSymbol to a ParserSymbol and then wrote
out its index -- generating a wildly wrong value.  This was okay at
runtime because the lexer only checks to see whether or not there is a
symbol and never uses its value.

However it looks like a pretty nasty error to anyone looking at the
generated source code.  Fixed by converting the GrammarSymbol to the
correct ParserSymbol when the lexer is written out.
2023-05-12 21:07:11 +12:00
Charles Baker
7f1b4c97c1 Optimize spontaneous and propagated lookahead in parser generator
Uses the algorithms described in Compilers - Principles, Techniques,
and Tools, p.241 to generate spontaneous lookaheads and propagate them
through the state machine.

Adds GrammarSymbolSet to store symbol sets as a bitmask by symbol index
and a vector of GrammarSymbol*.

Multi-threads the calculation of goto items for lookahead propagation.
2023-05-10 20:41:14 +12:00
Charles Baker
2a442d2667 Write parser state machines as GraphViz dot graphs 2023-04-21 20:23:47 +12:00
Charles Baker
c77e4d5a7b Only allocate GrammarState when needed in GrammarGenerator::goto_ 2023-04-18 15:17:14 +12:00
Charles Baker
85472d7b9e Use vector of transitions by symbol index for transitions between states 2023-04-18 15:17:14 +12:00
Charles Baker
6b4285bc78 Bump standard to c++14 for std::make_unique() 2023-04-18 15:06:55 +12:00
Charles Baker
3c810e1a74 Generate state machine from kernel items only 2023-04-17 13:26:43 +12:00
Charles Baker
390e8fc8f1 Add lalr library to all build target 2023-04-17 13:08:47 +12:00
Charles Baker
5a0e55bddf Use set not std::set in GrammarGenerator 2023-04-17 13:06:53 +12:00
Charles Baker
7d1b6cd2a2 Take precedence and associativity from either form of an implicit terminal
Sets the precedence and associativity of an implicit terminal from the
literal or identifier that sets it.  It's an error for both the terminal
and the identifier to set it.
2023-04-01 20:04:47 +13:00
Charles Baker
b0e68cf7a9 Check that implicit terminals only specify associativity on one symbol
Implicit terminals can be identified by their literal value or by the
identifier that names them.  But if both forms are used to specify an
associativity and precedence then it's not clear which one is correct.
Make it an error if associativity is specified for a terminal by its
literal and its identifier.
2023-04-01 20:04:47 +13:00
Charles Baker
23297a4aed Report the line that an unreferenced symbol is referenced from 2023-04-01 20:04:11 +13:00
Charles Baker
4f98975d88 LINT: Remove extra whitespace in comment in GrammarGenerator.cpp 2023-04-01 20:04:06 +13:00
Charles Baker
bc8a6dbebc Report symbol in syntax error if available 2023-03-22 20:40:47 +13:00
Charles Baker
305b73ebf4 Improve whitespace handling
Scan for whitespace until no whitespace token matches and reset the
position to the start of scanning so that whitespace prefixes that are
also valid tokens aren't skipped.
2023-03-21 21:11:01 +13:00
Charles Baker
0338ed6d21 Use PositionIterator to track line number in lexer actions 2023-03-21 21:10:32 +13:00
Charles Baker
4e39f61337 Revise examples to use simpler lexer actions 2023-03-21 21:04:54 +13:00
Charles Baker
18cf324d7b Revise regex tests with PositionIterator counting lines correctly 2023-03-21 21:04:54 +13:00
Charles Baker
db29a3b8eb Use PositionIterator to track line and column in lexer actions 2023-03-21 21:04:54 +13:00
Charles Baker
a47cd5c6d0 Improve reporting of syntax errors 2023-03-21 21:04:15 +13:00
Charles Baker
305c872c11 Back-track to most recently matched token in lexer
Back-tracks to the most recently matched symbol and lexeme if a run
continues but doesn't match anoter symbol.  Allows tokens that are
prefixes of other longer tokens to be matched after attempting to match
the longer token fails.
2023-03-21 21:03:40 +13:00
Charles Baker
ed7597a01a Add string_literal lexer action for single-character delimited strings 2023-03-21 21:01:45 +13:00
Charles Baker
4ba5dcbac3 Allow lexer actions for tokens and whitespace to co-exist
Previously action handlers for tokens and whitespace were stored in the
same vector.  But indices for the tokens and whitespace were overlapped
because they are generated for two separate state machines.  Separating
them into their own vectors allows the two to work together.
2023-03-21 20:48:11 +13:00
Charles Baker
408dc7b985 Separate block_comment() and line_comment() to simplify comments 2023-03-15 20:30:29 +13:00
Charles Baker
f68bb59f6f Propagate errors generating lexers up so they don't generate grammars 2023-03-09 16:56:13 +13:00
Charles Baker
adc77da58f Generate errors for undefined symbols not referenced by %precedence
Improves error detection of undefined symbols to included symbols
referenced in precedence directives but not defined as terminals or
referenced from %precedence directives.  Symbols referenced from
%precedence directives are assumed to be dummy terminals used to set
the precedence for a particular production.
2023-03-09 16:56:13 +13:00
Charles Baker
ff23037ec7 LINT: Improve comments in GrammarGenerator 2023-03-09 16:56:13 +13:00
Charles Baker
75b7f768e0 Test matching case insensitive keywords with regular expressions 2023-01-28 16:44:43 +13:00
Charles Baker
f8dd0b6986 Build with Forge v0.9.0 on Github Actions 2022-08-12 16:20:11 +12:00
Charles Baker
47b3ed8020 Call run() not system() in Lalrc.build() 2022-08-12 16:07:26 +12:00
Charles Baker
4608c46192 Update UnitTest++ to build with Forge v0.9.0 2022-08-12 16:03:28 +12:00
Charles Baker
f5e6c471d3 Update lalr Forge module to work with Forge v0.9.0 2022-08-12 16:01:48 +12:00