From af174cc09a25eb840d0eb57bab181d39884ac265 Mon Sep 17 00:00:00 2001 From: Ryan Pitasky <111201305+rpitasky@users.noreply.github.com> Date: Thu, 28 Nov 2024 01:27:57 -0500 Subject: [PATCH] parse: Equation invocations These are things like `Y1(1` --- test-files/programs/basic_note/BNOTECE.8xp | Bin 0 -> 6251 bytes test-files/programs/basic_note/BNOTECE2.8xp | Bin 0 -> 6255 bytes .../src/parse/components/data_access.rs | 47 ++++++++++++++++++ .../src/parse/components/mod.rs | 24 +++++++-- ti-basic-optimizer/src/parse/expression.rs | 11 ++-- 5 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 test-files/programs/basic_note/BNOTECE.8xp create mode 100644 test-files/programs/basic_note/BNOTECE2.8xp diff --git a/test-files/programs/basic_note/BNOTECE.8xp b/test-files/programs/basic_note/BNOTECE.8xp new file mode 100644 index 0000000000000000000000000000000000000000..11fbaf2f6c02fc0dff5a15d8e99bbb1fa389a185 GIT binary patch literal 6251 zcmdT|&2v-N6^HPQ9b%@^j_IcE#+j!VGVi_*>B%s@$g*r?fov=%7&@j?8&6Xsf~3$z zH%uB&{sJ#D)3WZuLyE8sC|qL`e?aKMfboQ;-N3e4xPL-_=id8d3A;0tcGHNw`_8@R zoqO*2{9VUlBiX?1i~aP_zI0{sS63%5c8ve7qj2T7m5Ispm5Y;=4!7fI$7d5CPE1~& zygE7Y$%mg#UUiNf-uLq(Ej{_ckxV+X?+}Qe9T6kBS3EY}8UA{PJ~|sD{CGSV34$P% z!y_2))K4!iDMiyHm~CrRxqW5r;Xe;sk?8b;M3DSq$@Amo z@lNKrrSVR?tD5Rbla$^}U;oMMKJ1}O9wX}|Rj_n)UKlYB|`=D}EJQJJZx%ivdnkruU^s@Lt{559G zwsJAhlg|uW(oC9=o7HoPjdN}lO>EY4Cr$?L~33>#4n{G%BdJ4JS&(ZB=Fn-AmMrr$c(4_w7sR3?esFs%oO%wF+IN9gyI^1_VI9Zb z3o!ID#x;{RASbLgC}l#>S~q{0pbZk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H|P wB2Gj?6A2;$O<<%yPc;7(VFcIIE!0UUg0O)W>hDIl0R0iQi1ecl`>JE|Urx+-4*&oF literal 0 HcmV?d00001 diff --git a/test-files/programs/basic_note/BNOTECE2.8xp b/test-files/programs/basic_note/BNOTECE2.8xp new file mode 100644 index 0000000000000000000000000000000000000000..84fd065d05ff8d1568b8b59dfd7a62e8ecb25d5f GIT binary patch literal 6255 zcmdT|-E&jN6^C$*9b%@^8`CFdI(6pihRogjAzc~9i!94V7TCsef}vwNwed7HB1j5- z=nF&R$zR}y%(OiBK|_l02Pmwui9aCp!GQ6ErhS3e=E40F`a8ROWeK}8H0?{HaQB|w zbI+bVpTBi1Hj)k8-q=qM?Ms&@e|2s0($VqX9nD|;ZFyocef830`KWvJ*wN1>KAf1m zGI?!s;*$?QoxB!5a(Lg*kF<0T431>dnSF;q{OpJr$-U;W@s9A}`c!z#^aY-qf=7LmG4nZ=NN~VIq8}D$u052p?u6RK*o(_`uB`}{RcEuEKNTaBV z1#vHZ3X93J;EE6Q_4UO)JQP=Qz)Po7DaZ}*@Qg}Zqsr|oYmfeU*os7_A0~q2=S!X+ zFO7FF$1RR`*qzl>cbcU1WP1BfW&3ld&kPI>ogL1PeDv|T(eoF6@#palv+FiAxFcqz zE^}fY+T0cQL`{4x?u$k7KrD%6@lbptR>Z1U6YJuUcr3mZPsCsJ=SofWTwQ;BYw>v7 zyMldl@y5m9U;O;w^4NhfW2~ihykl(N*#5D16yFEsW8%5k6feZz#MV^d@~2nC_u{WH zqtePnfA>IU*pi;Iy3b_J;5Bd4gVDpGhf5ES9zH$d^hnSn;2R4+(D(c)-;gg67M)sh z+*_D<#VlsU262R0aqpO!$GINhyle8bOX9AH`4t#r6%+Gf&NR(#N!7&c0C?BLya|KQ z`kD!UBfn6zY>XTXE4Fg-689r3-}ZQ<0jpwzzewAu*+Lka5y z_MV5KmocuHv;jF`wLvKpg4VkDs|0P>D5jI-Op7(-LBa0QF5lZeGJ{ zO|Hz*Y~$vNiBws|uZ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1PI2TSWjWIED|K4O1J-lm*rrCPWFxD) zwEX;h0jF%587RO|NU-e5rp%W3lrRY;*fXHsT<9jPwN&FrJz`p+w}TS!+uH$$J(0_n z(ppsrhbm0HVd35Df{SoSz#>&gh_A^EjocJL7C0N)dmmc3#E&gjpS1%g`l6*i3I}Ff z=pwAQktxU^GWz*u|5QdJz)-eAh5bN<{n8Z*AC`?_I9Uf2f3CY~HhL8Zk`=>13)jPC z9gvZ5KE#?K|DdwRUNEBxEHpV*I}EW}-a&k2Xm^&g9Sgo0?R8t~rb5>i>KS#^#51J` z41php5OGeEgxH2ISea2x6*jPR#ioBYl6t!CNN3d&N0GRX5NOQ1 ziu5(, +} + +impl EquationIndex { + pub fn parse( + subject: EquationName, + token: Token, + more: &mut Tokens, + ) -> Result, TokenReport> { + if token != Token::OneByte(0x10) { + return Ok(None); + } + + let index = expect_some!( + Expression::parse(next_or_err!(more)?, more)?, + more, + "an expression", + "This is a equation invocation and equation invocations require an index." + )?; + + if more.peek() == Some(Token::OneByte(0x11)) { + more.next(); + } + + Ok(Some(EquationIndex { + subject, + index: Box::new(index), + })) + } +} + +impl Reconstruct for EquationIndex { + fn reconstruct(&self, config: &Config) -> Vec { + let mut data = self.subject.reconstruct(config); + data.push(Token::OneByte(0x10)); + data.extend(self.index.reconstruct(config)); + data.push(Token::OneByte(0x11)); + + data + } +} diff --git a/ti-basic-optimizer/src/parse/components/mod.rs b/ti-basic-optimizer/src/parse/components/mod.rs index 18d4f6f..2715cad 100644 --- a/ti-basic-optimizer/src/parse/components/mod.rs +++ b/ti-basic-optimizer/src/parse/components/mod.rs @@ -1,7 +1,7 @@ use crate::error_reporting::TokenReport; pub use crate::parse::components::{ binary_operator::BinOp, - data_access::{ListIndex, ListIndexable, MatrixIndex, MatrixIndexable}, + data_access::{EquationIndex, ListIndex, ListIndexable, MatrixIndex, MatrixIndexable}, delvar_target::DelVarTarget, equation_name::EquationName, function_call::FunctionCall, @@ -73,9 +73,11 @@ pub enum Operand { NumericVarName(NumericVarName), ListName(ListName), MatrixName(MatrixName), + StringName(StringName), + EquationName(EquationName), ListAccess(ListIndex), MatrixAccess(MatrixIndex), - StringName(StringName), + EquationAccess(EquationIndex), Ans, I, GetKey, @@ -132,6 +134,20 @@ impl Parse for Operand { Ok(None) } } + Token::TwoByte(0x5E, 0x10..=0x2B | 0x40..=0x45 | 0x80..=0x82) => { + if let Some(name) = EquationName::parse(token, more)? { + if more.peek() == Some(Token::OneByte(0x10)) { + Ok( + EquationIndex::parse(name, more.next().unwrap(), more)? + .map(Self::EquationAccess), + ) + } else { + Ok(Some(Self::EquationName(name))) + } + } else { + Ok(None) + } + } Token::TwoByte(0x63, 0x2A) => Ok(Some(Self::TblInput)), // todo: TblIndex(n) list access Token::TwoByte(0x63, 0x00..=0x2A | 0x32..=0x38) => { Ok(WindowVarName::parse(token, more)?.map(Self::WindowVarName)) @@ -147,9 +163,11 @@ impl Reconstruct for Operand { Operand::NumericVarName(x) => x.reconstruct(config), Operand::ListName(x) => x.reconstruct(config), Operand::MatrixName(x) => x.reconstruct(config), + Operand::StringName(x) => x.reconstruct(config), + Operand::EquationName(x) => x.reconstruct(config), Operand::ListAccess(x) => x.reconstruct(config), Operand::MatrixAccess(x) => x.reconstruct(config), - Operand::StringName(x) => x.reconstruct(config), + Operand::EquationAccess(x) => x.reconstruct(config), Operand::Ans => vec![Token::OneByte(0x72)], Operand::I => vec![Token::OneByte(0x2C)], Operand::GetKey => vec![Token::OneByte(0xAD)], diff --git a/ti-basic-optimizer/src/parse/expression.rs b/ti-basic-optimizer/src/parse/expression.rs index 8768a7c..6878e1b 100644 --- a/ti-basic-optimizer/src/parse/expression.rs +++ b/ti-basic-optimizer/src/parse/expression.rs @@ -120,11 +120,12 @@ impl<'a> Builder<'a> { if let Some(Token::OneByte(0x10)) = self.tokens.peek() { // ( - match &operand { - Operand::Ans => { - unimplemented!() - } - _ => {} + if let Operand::Ans = &operand { + Err(TokenReport::new( + self.tokens.current_position(), + "Unsupported Ans( operation", + None, + ))? } }