4 ms·
> since the ones I looked at use crude, regex-based parsers that don't maintain information about the structure. It's assembly, not anything like C, C++, etc.
by tenebrisalietum 6y ago
> since the ones I looked at use crude, regex-based parsers that don't maintain information about the structure.
It's assembly, not anything like C, C++, etc. It's simple. You're supposed to be able to handle it with regexes.
> If you are looking for a hand-written lexer and parser for RISC-V assembly that builds a parse tree
Huh? Parse tree for assembly?
> For example, "xor xor, xor, xor, xor" will be parsed just fine, despite it not being legal RISC-V assembly.
Then ... why parse it??????
See, this is what happens when you refer to assembling as compiling. They are not the same.
- e19293001 6y agoYes. If basic assembler. No. If you're going to implement an assembler that supports constants and symbols which can be combined into expressions. And expressions can easily be parsed for example[0]: 〈primary expression〉->〈constant〉|〈symbol〉|〈local operand〉|@| (〈expression〉)|〈unary operator〉〈primary expression〉 〈term〉->〈primary expression〉|〈term〉〈strong operator〉〈primary expression〉 〈expression〉->〈term〉|〈expression〉〈weak operator〉〈term〉 〈unary operator〉-> + | − | ~ | $ | & 〈strong operator〉-> * | / | // | % | << | >> | & 〈weak operator〉-> + | − | | | ^ Your code might be hard to read if you'll not create a parse tree for it. [0] - http://www.mmix.cs.hm.edu/doc/mmixal.pdf http://www.mmix.cs.hm.edu/doc/mmixal.pdf
- pjmlp 6y agoOnly if you want a crude Assembler, if you want something like MASM/TASM, then one needs definitely a proper parser.
- tom_mellior 6y ago> Huh? Parse tree for assembly? Why not? The structure you need to represent something like lea eax, [eax + eax * 4] is tree-shaped. It's not as general as many other parse trees, since you don't have arbitrary nesting. But it is a tree-shaped thing that represents a parse, and if you need a name for it, "parse tree" is reasonable. The list containing all the labels/instructions/whatnot in the program is also a trivial tree. (I'm aware that RISC-V addressing modes are probably simpler than the x86 example above.)